[PATCH] Listing cpp source code in mainless binaries

Luis Machado
2008-06-10T18:44:18Z

An annoying situation occurs when trying to display CPP source code with
the list command when we use a binary that does not have a main
function.

When selecting a random source file to display, GDB only skips header
files, not the "<<C++-namespaces>>" symtab entry for, i believe, global
namespaces. Thus, GDB won't list the source code (below). This small
patch fixes this.

(gdb) l
1 <<C++-namespaces>>: No such file or directory.
in <<C++-namespaces>>

Regards,
Luis

2008-10-06 Luis Machado <luisgpm@br.ibm.com>

* source.c (select_source_symtab): Make sure we skip namespace
symtabs when showing cpp source code.

Index: gdb/source.c
===================================================================
--- gdb.orig/source.c 2008-05-19 08:50:10.000000000 -0700
+++ gdb/source.c 2008-06-10 11:15:01.000000000 -0700
@@ -250,7 +250,8 @@
return;
}

- /* All right; find the last file in the symtab list (ignoring .h's). */
+ /* All right; find the last file in the symtab list (ignoring .h's)
+ and namespace symtabs. */

current_source_line = 1;

@@ -260,7 +261,8 @@
{
const char *name = s->filename;
int len = strlen (name);
- if (!(len > 2 && strcmp(&name[len - 2], ".h") == 0))
+ if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
+ || strcmp (name, "<<C++-namespaces>>") == 0)))
current_source_symtab = s;
}
}