Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Listing cpp source code in mainless binaries
@ 2008-06-10 22:04 Luis Machado
  2008-06-26 14:42 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Luis Machado @ 2008-06-10 22:04 UTC (permalink / raw)
  To: gdb-patches

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;
 	}
     }



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Listing cpp source code in mainless binaries
  2008-06-10 22:04 [PATCH] Listing cpp source code in mainless binaries Luis Machado
@ 2008-06-26 14:42 ` Daniel Jacobowitz
  2008-06-30 14:13   ` Luis Machado
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2008-06-26 14:42 UTC (permalink / raw)
  To: Luis Machado; +Cc: gdb-patches

On Tue, Jun 10, 2008 at 03:28:45PM -0300, Luis Machado wrote:
> -  /* 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.  */

That should be inside the parentheses :-)

> @@ -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;
>  	}
>      }
> 

Also, the same check is needed a few lines down.  Otherwise OK.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Listing cpp source code in mainless binaries
  2008-06-26 14:42 ` Daniel Jacobowitz
@ 2008-06-30 14:13   ` Luis Machado
  2008-06-30 18:04     ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Luis Machado @ 2008-06-30 14:13 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches


On Thu, 2008-06-26 at 10:17 -0400, Daniel Jacobowitz wrote:
> On Tue, Jun 10, 2008 at 03:28:45PM -0300, Luis Machado wrote:
> > -  /* 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.  */
> 
> That should be inside the parentheses :-)
> 
> > @@ -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;
> >  	}
> >      }
> > 
> 
> Also, the same check is needed a few lines down.  Otherwise OK.
> 

Checked the following in with comment fixes.

Thanks!
Luis


2008-06-30  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-30 06:36:26.000000000 -0700
@@ -250,7 +250,8 @@
 	return;
     }
 
-  /* All right; find the last file in the symtab list (ignoring .h's).  */
+  /* Alright; find the last file in the symtab list (ignoring .h's
+     and namespace symtabs).  */
 
   current_source_line = 1;
 
@@ -260,14 +261,15 @@
 	{
 	  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;
 	}
     }
   if (current_source_symtab)
     return;
 
-  /* Howabout the partial symbol tables? */
+  /* How about the partial symbol tables?  */
 
   for (ofp = object_files; ofp != NULL; ofp = ofp->next)
     {
@@ -275,7 +277,8 @@
 	{
 	  const char *name = ps->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)))
 	    cs_pst = ps;
 	}
     }


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Listing cpp source code in mainless binaries
  2008-06-30 14:13   ` Luis Machado
@ 2008-06-30 18:04     ` Andreas Schwab
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2008-06-30 18:04 UTC (permalink / raw)
  To: luisgpm; +Cc: Daniel Jacobowitz, gdb-patches

Luis Machado <luisgpm@linux.vnet.ibm.com> writes:

> @@ -260,14 +261,15 @@
>  	{
>  	  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)))

Indentation is wrong here.

> @@ -275,7 +277,8 @@
>  	{
>  	  const char *name = ps->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)))

Likewise.  Alternatively, drop the inner pair of parens, the semantics
will be the same.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-30 14:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-10 22:04 [PATCH] Listing cpp source code in mainless binaries Luis Machado
2008-06-26 14:42 ` Daniel Jacobowitz
2008-06-30 14:13   ` Luis Machado
2008-06-30 18:04     ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox