Author: akhaldi
Date: Sun Aug 18 20:05:32 2013
New Revision: 59775
URL:
http://svn.reactos.org/svn/reactos?rev=59775&view=rev
Log:
[RSYM]
* Add a flag (-s) to pass the source folder. This allows it to set the debug file paths
relatively to that source folder. Brought to you by Arty.
[CMAKE]
* Leverage the new rsym flag. The rossym file paths are no longer absolute.
Modified:
trunk/reactos/cmake/gcc.cmake
trunk/reactos/tools/rsym/rsym.c
Modified: trunk/reactos/cmake/gcc.cmake
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/cmake/gcc.cmake?rev=59775&…
==============================================================================
--- trunk/reactos/cmake/gcc.cmake [iso-8859-1] (original)
+++ trunk/reactos/cmake/gcc.cmake [iso-8859-1] Sun Aug 18 20:05:32 2013
@@ -143,16 +143,16 @@
get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG)
set(CMAKE_C_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS>
<LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
- "${RSYM} <TARGET> <TARGET>")
+ "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
set(CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS>
<LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
- "${RSYM} <TARGET> <TARGET>")
+ "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
set(CMAKE_C_CREATE_SHARED_LIBRARY
"<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS}
<CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS>
<CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS>
<LINK_LIBRARIES>"
- "${RSYM} <TARGET> <TARGET>")
+ "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
"<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS}
<CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS>
<CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS>
<LINK_LIBRARIES>"
- "${RSYM} <TARGET> <TARGET>")
+ "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
set(CMAKE_RC_CREATE_SHARED_LIBRARY
"<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS}
<CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS>
<CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS>
<LINK_LIBRARIES>")
endif()
Modified: trunk/reactos/tools/rsym/rsym.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rsym/rsym.c?rev=5977…
==============================================================================
--- trunk/reactos/tools/rsym/rsym.c [iso-8859-1] (original)
+++ trunk/reactos/tools/rsym/rsym.c [iso-8859-1] Sun Aug 18 20:05:32 2013
@@ -464,6 +464,8 @@
ULONG NumberOfSymbols;
void *process;
DWORD module_base;
+ char *PathChop;
+ char *SourcePath;
struct DbgHelpLineEntry *lastLineEntry;
};
@@ -530,6 +532,21 @@
int i = id >> 10;
int bucket = id & 0x3ff;
return tab->Table[bucket][i];
+}
+
+/* Remove a prefix of PathChop if it exists and return a copy of the tail. */
+static char *
+StrDupShortenPath(char *PathChop, char *FilePath)
+{
+ int pclen = strlen(PathChop);
+ if (!strncmp(FilePath, PathChop, pclen))
+ {
+ return strdup(FilePath+pclen);
+ }
+ else
+ {
+ return strdup(FilePath);
+ }
}
static BOOL
@@ -542,7 +559,48 @@
if (!pSymbol) return FALSE;
memset(pSymbol, 0, FIELD_OFFSET(SYMBOL_INFO, Name[MAX_SYM_NAME]));
- fileId = DbgHelpAddStringToTable(tab, strdup(LineInfo->FileName));
+ /* If any file can be opened by relative path up to a certain level, then
+ record that path. */
+ if (!tab->PathChop)
+ {
+ int i, endLen;
+ char *end = strrchr(LineInfo->FileName, '/');
+
+ if (!end)
+ end = strrchr(LineInfo->FileName, '\\');
+
+ if (end)
+ {
+ for (i = (end - LineInfo->FileName) - 1; i >= 0; i--)
+ {
+ if (LineInfo->FileName[i] == '/' || LineInfo->FileName[i]
== '\\')
+ {
+ char *synthname = malloc(strlen(tab->SourcePath) +
+ strlen(LineInfo->FileName + i + 1)
+ + 2);
+ strcpy(synthname, tab->SourcePath);
+ strcat(synthname, "/");
+ strcat(synthname, LineInfo->FileName + i + 1);
+ FILE *f = fopen(synthname, "r");
+ free(synthname);
+ if (f)
+ {
+ fclose(f);
+ break;
+ }
+ }
+ }
+
+ i++; /* Be in the string or past the next slash */
+ tab->PathChop = malloc(i + 1);
+ memcpy(tab->PathChop, LineInfo->FileName, i);
+ tab->PathChop[i] = 0;
+ }
+ }
+
+ fileId = DbgHelpAddStringToTable(tab,
+ StrDupShortenPath(tab->PathChop,
+ LineInfo->FileName));
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME;
@@ -570,7 +628,7 @@
}
static int
-ConvertDbgHelp(void *process, DWORD module_base,
+ConvertDbgHelp(void *process, DWORD module_base, char *SourcePath,
ULONG *SymbolsCount, PROSSYM_ENTRY *SymbolsBase,
ULONG *StringsLength, void **StringsBase)
{
@@ -589,6 +647,8 @@
strtab.CurLineEntries = 0;
strtab.LineEntries = 16384;
strtab.LineEntryData = calloc(strtab.LineEntries, sizeof(struct DbgHelpLineEntry));
+ strtab.PathChop = NULL;
+ strtab.SourcePath = SourcePath ? SourcePath : "";
SymEnumLines(process, module_base, NULL, NULL, DbgHelpAddLineNumber, &strtab);
@@ -636,6 +696,7 @@
}
free(strtab.LineEntryData);
+ free(strtab.PathChop);
qsort(*SymbolsBase, *SymbolsCount, sizeof(ROSSYM_ENTRY), (int (*)(const void *, const
void *))CompareSymEntry);
@@ -1123,15 +1184,47 @@
void *file;
char elfhdr[4] = { '\177', 'E', 'L', 'F' };
BOOLEAN UseDbgHelp = FALSE;
-
- if (argc != 3)
- {
- fprintf(stderr, "Usage: rsym <exefile> <symfile>\n");
+ int arg, argstate = 0;
+ char *SourcePath = NULL;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ switch (argstate)
+ {
+ default:
+ argstate = -1;
+ break;
+
+ case 0:
+ if (!strcmp(argv[arg], "-s"))
+ {
+ argstate = 1;
+ }
+ else
+ {
+ argstate = 2;
+ path1 = convert_path(argv[arg]);
+ }
+ break;
+
+ case 1:
+ free(SourcePath);
+ SourcePath = strdup(argv[arg]);
+ argstate = 0;
+ break;
+
+ case 2:
+ path2 = convert_path(argv[arg]);
+ argstate = 3;
+ break;
+ }
+ }
+
+ if (argstate != 3)
+ {
+ fprintf(stderr, "Usage: rsym [-s <sources>] <input>
<output>\n");
exit(1);
}
-
- path1 = convert_path(argv[1]);
- path2 = convert_path(argv[2]);
FileData = load_file(path1, &FileSize);
if (!FileData)
@@ -1192,6 +1285,7 @@
if (ConvertDbgHelp(FileData,
module_base,
+ SourcePath,
&StabSymbolsCount,
&StabSymbols,
&StringsLength,