1 http://sourceware.org/ml/gdb-patches/2009-10/msg00508.html
2 Subject: [patch 3/3] debug-file-directory with multiple components
6 for various reasons `debug-file-directory' would be sometimes useful to have
7 multiple components such as `solib-search-path' has.
9 I found it useful myself during various separate debuginfo tests/scripts.
11 It was requested for the ABRT bugreporting project at the preceding mail of:
12 https://fedorahosted.org/pipermail/crash-catcher/2009-October/000054.html
14 It should be a backward compatible extension as DIRNAME_SEPARATOR should never
15 be a valid part of a single DEBUG_FILE_DIRECTORY component.
23 2009-10-22 Jan Kratochvil <jan.kratochvil@redhat.com>
25 * gdb.texinfo (set debug-file-directory, show debug-file-directory)
26 (Auto-loading): Use plural and note one can use multiple components now.
29 2009-10-22 Jan Kratochvil <jan.kratochvil@redhat.com>
31 * symfile.c (build_id_to_debug_filename): New variable debugdir. Move
32 variables size, s and data into a new inner block. Change xmalloc for
33 alloca, use direct BUILDID->SIZE there now. Loop for the
34 DEBUG_FILE_DIRECTORY components.
35 (find_separate_debug_file): New variable debugdir and debugdir_end.
36 Loop for the DEBUG_FILE_DIRECTORY components.
37 (_initialize_symfile): For "debug-file-directory" use plural and note
38 one can use multiple components now.
41 2009-10-22 Jan Kratochvil <jan.kratochvil@redhat.com>
43 * gdb.base/sepdebug.exp: New test_different_dir call for multiple-dirs.
45 --- a/gdb/doc/gdb.texinfo
46 +++ b/gdb/doc/gdb.texinfo
47 @@ -14066,13 +14066,14 @@ name @value{GDBN} is currently using.
50 @kindex set debug-file-directory
51 -@item set debug-file-directory @var{directory}
52 -Set the directory which @value{GDBN} searches for separate debugging
53 -information files to @var{directory}.
54 +@item set debug-file-directory @var{directories}
55 +Set the directories which @value{GDBN} searches for separate debugging
56 +information files to @var{directory}. Multiple directory components can be set
57 +concatenating them by a directory separator.
59 @kindex show debug-file-directory
60 @item show debug-file-directory
61 -Show the directory @value{GDBN} searches for separate debugging
62 +Show the directories @value{GDBN} searches for separate debugging
66 @@ -19336,8 +19337,8 @@ readable, @value{GDBN} will evaluate it as a Python script.
68 If this file does not exist, and if the parameter
69 @code{debug-file-directory} is set (@pxref{Separate Debug Files}),
70 -then @value{GDBN} will use the file named
71 -@file{@var{debug-file-directory}/@var{real-name}}, where
72 +then @value{GDBN} will use for its each separated directory component
73 +@code{component} the file named @file{@code{component}/@var{real-name}}, where
74 @var{real-name} is the object file's real name, as described above.
76 Finally, if this file does not exist, then @value{GDBN} will look for
79 @@ -1218,35 +1218,59 @@ build_id_verify (const char *filename, struct build_id *check)
81 build_id_to_debug_filename (struct build_id *build_id)
83 - char *link, *s, *retval = NULL;
84 - gdb_byte *data = build_id->data;
85 - size_t size = build_id->size;
86 + char *link, *debugdir, *retval = NULL;
88 /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
89 - link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
90 - + 2 * size + (sizeof ".debug" - 1) + 1);
91 - s = link + sprintf (link, "%s/.build-id/", debug_file_directory);
95 - s += sprintf (s, "%02x", (unsigned) *data++);
100 - s += sprintf (s, "%02x", (unsigned) *data++);
101 - strcpy (s, ".debug");
103 - /* lrealpath() is expensive even for the usually non-existent files. */
104 - if (access (link, F_OK) == 0)
105 - retval = lrealpath (link);
108 - if (retval != NULL && !build_id_verify (retval, build_id))
109 + link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
110 + + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
112 + /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
113 + cause "/.build-id/..." lookups. */
115 + debugdir = debug_file_directory;
120 + char *s, *debugdir_end;
121 + gdb_byte *data = build_id->data;
122 + size_t size = build_id->size;
124 + while (*debugdir == DIRNAME_SEPARATOR)
127 + debugdir_end = strchr (debugdir, DIRNAME_SEPARATOR);
128 + if (debugdir_end == NULL)
129 + debugdir_end = &debugdir[strlen (debugdir)];
131 + memcpy (link, debugdir, debugdir_end - debugdir);
132 + s = &link[debugdir_end - debugdir];
133 + s += sprintf (s, "/.build-id/");
137 + s += sprintf (s, "%02x", (unsigned) *data++);
142 + s += sprintf (s, "%02x", (unsigned) *data++);
143 + strcpy (s, ".debug");
145 + /* lrealpath() is expensive even for the usually non-existent files. */
146 + if (access (link, F_OK) == 0)
147 + retval = lrealpath (link);
149 + if (retval != NULL && !build_id_verify (retval, build_id))
155 + if (retval != NULL)
158 + debugdir = debugdir_end;
160 + while (*debugdir != 0);
164 @@ -1333,7 +1357,7 @@ static char *
165 find_separate_debug_file (struct objfile *objfile)
168 - char *basename, *name_copy;
169 + char *basename, *name_copy, *debugdir;
171 char *debugfile = NULL;
172 char *canon_name = NULL;
173 @@ -1410,29 +1434,51 @@ find_separate_debug_file (struct objfile *objfile)
174 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
175 goto cleanup_return_debugfile;
177 - /* Then try in the global debugfile directory. */
178 - strcpy (debugfile, debug_file_directory);
179 - strcat (debugfile, "/");
180 - strcat (debugfile, dir);
181 - strcat (debugfile, basename);
183 - if (separate_debug_file_exists (debugfile, crc32, objfile->name))
184 - goto cleanup_return_debugfile;
185 + /* Then try in the global debugfile directories.
187 + Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
188 + cause "/..." lookups. */
190 - /* If the file is in the sysroot, try using its base path in the
191 - global debugfile directory. */
193 - && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
194 - && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
195 + debugdir = debug_file_directory;
198 - strcpy (debugfile, debug_file_directory);
199 - strcat (debugfile, canon_name + strlen (gdb_sysroot));
200 + char *debugdir_end;
202 + while (*debugdir == DIRNAME_SEPARATOR)
205 + debugdir_end = strchr (debugdir, DIRNAME_SEPARATOR);
206 + if (debugdir_end == NULL)
207 + debugdir_end = &debugdir[strlen (debugdir)];
209 + memcpy (debugfile, debugdir, debugdir_end - debugdir);
210 + debugfile[debugdir_end - debugdir] = 0;
211 strcat (debugfile, "/");
212 + strcat (debugfile, dir);
213 strcat (debugfile, basename);
215 if (separate_debug_file_exists (debugfile, crc32, objfile->name))
216 goto cleanup_return_debugfile;
218 + /* If the file is in the sysroot, try using its base path in the
219 + global debugfile directory. */
221 + && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
222 + && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
224 + memcpy (debugfile, debugdir, debugdir_end - debugdir);
225 + debugfile[debugdir_end - debugdir] = 0;
226 + strcat (debugfile, canon_name + strlen (gdb_sysroot));
227 + strcat (debugfile, "/");
228 + strcat (debugfile, basename);
230 + if (separate_debug_file_exists (debugfile, crc32, objfile->name))
231 + goto cleanup_return_debugfile;
234 + debugdir = debugdir_end;
236 + while (*debugdir != 0);
240 @@ -4173,12 +4219,12 @@ Usage: set extension-language .foo bar"),
242 add_setshow_optional_filename_cmd ("debug-file-directory", class_support,
243 &debug_file_directory, _("\
244 -Set the directory where separate debug symbols are searched for."), _("\
245 -Show the directory where separate debug symbols are searched for."), _("\
246 +Set the directories where separate debug symbols are searched for."), _("\
247 +Show the directories where separate debug symbols are searched for."), _("\
248 Separate debug symbols are first searched for in the same\n\
249 directory as the binary, then in the `" DEBUG_SUBDIRECTORY "' subdirectory,\n\
250 and lastly at the path of the directory of the binary with\n\
251 -the global debug-file directory prepended."),
252 +each global debug-file-directory component prepended."),
254 show_debug_file_directory,
255 &setlist, &showlist);
256 --- a/gdb/testsuite/gdb.base/sepdebug.exp
257 +++ b/gdb/testsuite/gdb.base/sepdebug.exp
258 @@ -995,6 +995,12 @@ if ![string compare $build_id_debug_filename ""] then {
260 test_different_dir build-id "${objdir}/${subdir}" $xfail
262 + # Test also multiple directories can be specified. Without the build-id
263 + # reference GDB would find the separate debug info just at the same
264 + # location as the executable file.
266 + test_different_dir multiple-dirs "/doesnotexist:${objdir}/${subdir}" $xfail
268 # Spare debug files may confuse testsuite runs in the future.
269 remote_exec build "rm -f ${objdir}/${subdir}/${build_id_debug_filename}"