Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jason Molenda <jmolenda@apple.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb@sourceware.org
Subject: Re: GDB Focus Group at the 2008 GCC Summit
Date: Mon, 23 Jun 2008 21:46:00 -0000	[thread overview]
Message-ID: <DBD59C91-2D0D-4AD6-A2C8-7F36833CFFEC@apple.com> (raw)
In-Reply-To: <20080619190942.GA3744@adacore.com>


On Jun 19, 2008, at 12:09 PM, Joel Brobecker wrote:

> |
> | * Fix and continue:
> |
> |     Perhaps try to implement this feature through the use of Python.
> |     For instance, use python to build a return value, and return  
> that.

As Jim mentioned, we did this to gdb here at Apple four or five years  
back.  I started my work on F&C by reading through HP's gdb changes  
(in "wdb", their version of gdb).  Their implementation is very gdb- 
centric and may be a better place to start looking - if I remember  
correctly gdb rebuilds the .o file itself as a part of the "fix"  
command, for instance.

With our F&C system, we start by compiling a PIC library from the .o  
file (a "bundle" on Mac OS X).  We've modified gcc to pad the  
prologues of functions with a few nop instructions and we've also  
changed the compiler to use indirect references to static objects  
within the compilation unit.  Normally a function accessing a file- 
static variable, would use a pic-based reference once it had been  
finished with the linker.  But we want to map these all to the  
original static/globals that we started with so we need the  
indirection.  (you don't want a global to have a value of 10, fix in a  
file and then one compilation unit thinks it has a value of 0 while  
the rest of the program is still pointing to the one with a 10.)

Before we load the newly built code, we try to look over the types in  
the .o file and ensure that arguments haven't been added to functions,  
structure sizes haven't been changed, etc.  Again, half of the program  
thinking that a function takes 2 arguments and another part thinking  
it takes 3 will work poorly.

Once the new .o file has been loaded into memory, we rewrite the nop's  
in the prologues of all earlier versions of the functions to point to  
the newest versions.  So if someone has a pointer to one of the  
original functions, they'll still end up calling the new one.  We  
update the indirection table for file statics so any references to  
globals/statics in the just-loaded .o file will go to the original  
versions, if they exist.

The IDE is responsible for removing & reinserting breakpoints at the  
correct line numbers.  If you had a breakpoint on main.c:35 and you  
added a couple of lines of code earlier in the file, that breakpoint  
needs to be moved to main.c:37.

If you're stopped in a function that was just updated, the IDE tells  
gdb to re-set to the corresponding line number in the newly loaded  
file.  This obviously has no chance of working except at -O0.  And  
with i386/ppc code, most functions that reference static/global data  
load $pc into a register so they can load objects pc-relative.  You  
need to find that setup in the new function, compute what that picbase  
register should hold and set it ahead of time.

gdb then marks the psymtab/symtab of the just-replaced file as  
'obsolete' so when we are doing a symbol-to-addr lookup we don't find  
them.  At the same time, if you're doing an addr-to-symbol lookup you  
want to find the old, obsoleted files -- you might have a function on  
the stack still or something like that.

As you can tell from the above, at Apple I offload some of the work to  
the compiler and some to the IDE.  You get the impression that the wdb  
folks did it all by themselves - they have all sorts of chicanery to  
squeeze the jump instruction into functions regardless of how long  
they are, or if you're stopped in the middle of the code it wants to  
rewrite.

All that being said, it's a pretty fragile mechanism.  C/C++ weren't  
designed for this kind of thing.  It works fine on trivial examples  
and makes great demoware but it's very easy to crash your program when  
you're trying to use this on real programs/real problems.  I've heard  
some success stories from people who are doing specific narrow things,  
or where re-starting their debug session and getting back to the  
problem spot are so expensive that they're willing to take a risk.   
But IMO, in practice, it's less useful than any of us would have liked.

wdb and Apple's gdb implementations are GPL'ed of course so for more  
details it's probably best to just browse the sources.

J


  parent reply	other threads:[~2008-06-23 21:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-19 19:10 Joel Brobecker
2008-06-22  6:08 ` Thiago Jung Bauermann
2008-06-22 11:52 ` Nick Roberts
2008-06-22 13:53   ` Joel Brobecker
2008-06-23 15:17   ` Tom Tromey
2008-06-23 17:35     ` Jim Ingham
2008-06-23 21:55     ` Nick Roberts
2008-06-23 15:16 ` Tom Tromey
2008-06-26  0:24   ` Tom Tromey
2008-07-03  3:27   ` Thiago Jung Bauermann
2008-07-03  8:12     ` Andreas Schwab
2008-07-03 12:35     ` Daniel Jacobowitz
2008-07-03 14:28       ` Thiago Jung Bauermann
2008-07-04  2:33       ` Tom Tromey
2008-07-04  3:19         ` Daniel Jacobowitz
2008-06-23 21:46 ` Jason Molenda [this message]
2008-06-23 22:22   ` Nick Roberts
2008-06-24 21:18     ` Nick Roberts
2008-06-25  6:56       ` [MI] changing breakpoint location (Was: GDB Focus Group at the 2008 GCC Summit) Vladimir Prus
2008-06-23 22:09 ` GDB Focus Group at the 2008 GCC Summit Mark Kettenis
2008-06-23 22:26   ` Joel Brobecker
2008-06-24  8:35   ` Andrew STUBBS
2008-06-24  8:56     ` Andreas Schwab
2008-06-24 18:12     ` Michael Snyder
2008-06-24 18:28     ` Daniel Jacobowitz
2008-06-24 19:33     ` Dave Korn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DBD59C91-2D0D-4AD6-A2C8-7F36833CFFEC@apple.com \
    --to=jmolenda@apple.com \
    --cc=brobecker@adacore.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox