Skip to content

Commit

Permalink
Using scanFileName variable instead of /proc file system.
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Zhang <[email protected]>
  • Loading branch information
zheddie committed Dec 4, 2019
1 parent 3986037 commit 96a156f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions ddr/include/ddr/scanner/dwarf/DwarfFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#ifndef DWARFFUNCTIONS_HPP
#define DWARFFUNCTIONS_HPP

#include "ddr/config.hpp"

Expand Down Expand Up @@ -324,3 +326,5 @@ int dwarf_dieoffset(Dwarf_Die die, Dwarf_Off *dieOffset, Dwarf_Error *error);
int dwarf_get_TAG_name(Dwarf_Half tag, const char **name);

void setError(Dwarf_Error *error, Dwarf_Half num);

#endif /*DWARFFUNCTIONS_HPP*/
5 changes: 3 additions & 2 deletions ddr/include/ddr/scanner/dwarf/DwarfScanner.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2018 IBM Corp. and others
* Copyright (c) 2015, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -73,8 +73,9 @@ class DwarfScanner : public Scanner

virtual DDR_RC startScan(OMRPortLibrary *portLibrary, Symbol_IR *ir,
vector<string> *debugFiles, const char *blacklistPath);

static const char * getScanFileName() { return scanFileName; }
private:
static const char * scanFileName;
Dwarf_Signed _fileNameCount;
char **_fileNamesTable;
unordered_map<string, int> _anonymousEnumNames;
Expand Down
9 changes: 3 additions & 6 deletions ddr/lib/ddr-scanner/dwarf/AixSymbolTableParser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2018 IBM Corp. and others
* Copyright (c) 2015, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -22,6 +22,7 @@
#include "ddr/error.hpp"

#include "ddr/scanner/dwarf/AixSymbolTableParser.hpp"
#include "ddr/scanner/dwarf/DwarfScanner.hpp"

/* Statics. */
static die_map createdDies;
Expand Down Expand Up @@ -105,7 +106,6 @@ dwarf_init(int fd,
int ret = DW_DLV_OK;
FILE *fp = NULL;
char buffer[50000];
char filepath[100] = {'\0'};
Dwarf_CU_Context::_firstCU = NULL;
Dwarf_CU_Context::_currentCU = NULL;
refNumber = 1;
Expand All @@ -114,13 +114,10 @@ dwarf_init(int fd,
ret = populateBuiltInTypeDies(error);
populateAttributeReferences();

/* Get the path of the file descriptor. */
sprintf(filepath, "/proc/%d/fd/%d", getpid(), fd);

/* Call dump to get the symbol table. */
if (DW_DLV_OK == ret) {
stringstream ss;
ss << "dump -tvXany " << filepath << " 2>&1";
ss << "dump -tvXany " << DwarfScanner::getScanFileName() << " 2>&1";
fp = popen(ss.str().c_str(), "r");
if (NULL == fp) {
ret = DW_DLV_ERROR;
Expand Down
4 changes: 4 additions & 0 deletions ddr/lib/ddr-scanner/dwarf/DwarfScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class DwarfVisitor : public TypeVisitor
virtual DDR_RC visitUnion(UnionUDT *type) const;
};

const char * DwarfScanner::scanFileName = NULL;

DwarfScanner::DwarfScanner()
: _fileNameCount(0), _fileNamesTable(NULL), _ir(NULL), _debug(NULL)
{
Expand Down Expand Up @@ -1563,6 +1565,7 @@ DwarfScanner::scanFile(OMRPortLibrary *portLibrary, Symbol_IR *ir, const char *f
Dwarf_Handler errhand = 0;
Dwarf_Ptr errarg = NULL;
intptr_t native_fd = omrfile_convert_omrfile_fd_to_native_fd(fd);
DwarfScanner::scanFileName = filepath;
res = dwarf_init((int)native_fd, access, errhand, errarg, &_debug, &error);
if (DW_DLV_OK != res) {
ERRMSG("Failed to initialize libDwarf scanning %s: %s\nExiting...\n", filepath, dwarf_errmsg(error));
Expand Down Expand Up @@ -1597,6 +1600,7 @@ DwarfScanner::scanFile(OMRPortLibrary *portLibrary, Symbol_IR *ir, const char *f
omrfile_close(fd);
}

DwarfScanner::scanFileName = NULL;
DEBUGPRINTF("Start Scan Finished: Returning...");

return rc;
Expand Down

0 comments on commit 96a156f

Please sign in to comment.