Skip to content

Commit

Permalink
Merge pull request #3447 from dnakamura/ddrgen
Browse files Browse the repository at this point in the history
DDR: allow ddr-scanner to handle exe/dll files
  • Loading branch information
charliegracie authored Feb 4, 2019
2 parents a8ca0e6 + 4feb2c3 commit 92f81f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ddr/include/ddr/scanner/pdb/PdbScanner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class PdbScanner : public Scanner
DDR_RC createClassUDT(IDiaSymbol *symbol, ClassUDT **newClass, NamespaceUDT *outerUDT);
DDR_RC createEnumUDT(IDiaSymbol *symbol, NamespaceUDT *outerUDT);
DDR_RC createTypedef(IDiaSymbol *symbol, NamespaceUDT *outerUDT);
DDR_RC loadDataFromPdb(const wchar_t *filename, IDiaDataSource **diaDataSource, IDiaSession **diaSession, IDiaSymbol **diaSymbol);
DDR_RC loadDataFromBinary(const wchar_t *filename, IDiaDataSource **diaDataSource, IDiaSession **diaSession, IDiaSymbol **diaSymbol);
DDR_RC setSuperClassName(IDiaSymbol *symbol, ClassUDT *newUDT);
void getNamespaceFromName(const string &name, NamespaceUDT **outerUDT);
static DDR_RC getName(IDiaSymbol *symbol, string *name);
Expand Down
23 changes: 18 additions & 5 deletions ddr/lib/ddr-scanner/pdb/PdbScanner.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 Down Expand Up @@ -143,7 +143,7 @@ PdbScanner::startScan(OMRPortLibrary *portLibrary, Symbol_IR *ir, vector<string>
const size_t len = file.length();
wchar_t *filename = new wchar_t[len + 1];
mbstowcs(filename, file.c_str(), len + 1);
rc = loadDataFromPdb(filename, &diaDataSource, &diaSession, &diaSymbol);
rc = loadDataFromBinary(filename, &diaDataSource, &diaSession, &diaSymbol);

if (DDR_RC_OK == rc) {
rc = addChildrenSymbols(diaSymbol, SymTagUDT, NULL);
Expand Down Expand Up @@ -189,9 +189,18 @@ PdbScanner::startScan(OMRPortLibrary *portLibrary, Symbol_IR *ir, vector<string>
}

DDR_RC
PdbScanner::loadDataFromPdb(const wchar_t *filename, IDiaDataSource **dataSource, IDiaSession **session, IDiaSymbol **symbol)
PdbScanner::loadDataFromBinary(const wchar_t *filename, IDiaDataSource **dataSource, IDiaSession **session, IDiaSymbol **symbol)
{
DDR_RC rc = DDR_RC_OK;
bool isPDBFile = false;
/* get location of the file extension */
const wchar_t *fileExtension = wcsrchr(filename, L'.');

/* check if file extension is '.pdb' */
if ((NULL!= fileExtension) && (0 == wcscmp(fileExtension, L".pdb"))){
isPDBFile = true;
}

/* Attemt to co-create the DiaSource instance. On failure to find the required
* dll, instead attempt to find and load the dll first.
*/
Expand Down Expand Up @@ -231,9 +240,13 @@ PdbScanner::loadDataFromPdb(const wchar_t *filename, IDiaDataSource **dataSource
}

if (DDR_RC_OK == rc) {
hr = (*dataSource)->loadDataFromPdb(filename);
if(isPDBFile){
hr = (*dataSource)->loadDataFromPdb(filename);
} else {
hr = (*dataSource)->loadDataForExe(filename, NULL, NULL);
}
if (FAILED(hr)) {
ERRMSG("loadDataFromPdb() failed for file with HRESULT = %08lX. Ensure the input is a pdb and not an exe.\nFile: %ls", hr, filename);
ERRMSG("loadDataFromPdb() failed for file with HRESULT = %08lX.\nFile: %ls", hr, filename);
rc = DDR_RC_ERROR;
}
}
Expand Down

0 comments on commit 92f81f4

Please sign in to comment.