public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* [Compile] Inserting compiled code via jumps
@ 2018-12-12 16:09 Paul Naert
  2018-12-15 22:54 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Naert @ 2018-12-12 16:09 UTC (permalink / raw)
  To: gdb

Hi,

I am a masters student and I would like to devote my research to  
improving GDB's GCC Compile and Execute by adding the possibility to  
jump directly to the compiled code without having to hit a breakpoint.

The idea is to reuse the same principle that was used in fast  
tracepoints to insert code in a compiled program, except that instead  
of jumping to GDB's collector function we would execute the code  
compiled by GCC each time we hit the selected instruction.


Given the code for compiling a snippet of C through GCC and the code  
for inserting fast tracepoint already exist, I think that this should  
be feasible.

What I was wondering is :
    -  Has someone already worked on this ? On the wiki page there are  
mentions to future projects that seem related (fast breakpoint  
conditions most notably)
    -  Do you see any reason why that would not work that I missed,  
except for the limitations of the existing Compile project?

Thank you,

Paul NAERT

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

* Re: [Compile] Inserting compiled code via jumps
  2018-12-12 16:09 [Compile] Inserting compiled code via jumps Paul Naert
@ 2018-12-15 22:54 ` Tom Tromey
  2018-12-17 17:01   ` Paul Naert
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2018-12-15 22:54 UTC (permalink / raw)
  To: Paul Naert; +Cc: gdb

>>>>> "Paul" == Paul Naert <paul.naert@polymtl.ca> writes:

Paul> I am a masters student and I would like to devote my research to
Paul> improving GDB's GCC Compile and Execute by adding the possibility to
Paul> jump directly to the compiled code without having to hit a breakpoint.

Paul> The idea is to reuse the same principle that was used in fast
Paul> tracepoints to insert code in a compiled program, except that instead
Paul> of jumping to GDB's collector function we would execute the code
Paul> compiled by GCC each time we hit the selected instruction.

I am not sure I really understand the idea.

With the "compile" command, we had hopes of someday extending it to
either allow fast breakpoint conditions (by compiling the breakpoint
condition and patching the process); or to allow fix-and-continue
(recompiling a single function and inserting it).

Is your idea like one of these?  If it's different, could you maybe show
an example of how a user would use it?

Paul>    -  Has someone already worked on this ? On the wiki page there are
Paul> mentions to future projects that seem related (fast breakpoint
Paul> conditions most notably)

As far as I know nobody is working on it.

Paul>    -  Do you see any reason why that would not work that I missed,
Paul> except for the limitations of the existing Compile project?

I think it's entirely possible.  I think the main issues involve the
patching -- figuring out how to replace instructions.  Maybe dyninst
could be used to help with the rewriting, or maybe it can be done purely
in gdb.

thanks,
Tom

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

* Re: [Compile] Inserting compiled code via jumps
  2018-12-15 22:54 ` Tom Tromey
@ 2018-12-17 17:01   ` Paul Naert
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Naert @ 2018-12-17 17:01 UTC (permalink / raw)
  To: tom; +Cc: gdb

Hi,
The idea is similar to fast breakpoints conditions, as gdb would need  
to patch in a jump to the compiled code directly or via a trampoline.  
Here is an example of how it could be used :

(gdb) fcompile file snippet.c test.c:8

// snippet.c is compiled via gcc. It could contain a call to an trace  
collector function for instance
// The instruction corresponding to line 8 of source file test.c is  
replaced by a jump to a trampoline
// In the trampoline we call _gdb_expr_(), and then execute the  
instruction that we replaced, corrected for displacement

(gdb) run

// The code from snippet.c is executed every time we hit line 8 of test.c

This would directly encompass fast breakpoint conditions, using a  
snippet like "if(cond) __asm__("int3");".
NB: this does not work right now because gdb does not debug the  
inserted snippet, but it should when injected via a jump.

The code for patching in the jump is located in gdbserver, I think  
there is no use for dyninst for this. I am currently trying to migrate  
what is necessary to a common directory.

If you need any more information let me know.

Thanks,

Paul

Tom Tromey <tom@tromey.com> wrote :

>>>>>> "Paul" == Paul Naert <paul.naert@polymtl.ca> writes:
>
> Paul> I am a masters student and I would like to devote my research to
> Paul> improving GDB's GCC Compile and Execute by adding the possibility to
> Paul> jump directly to the compiled code without having to hit a breakpoint.
>
> Paul> The idea is to reuse the same principle that was used in fast
> Paul> tracepoints to insert code in a compiled program, except that instead
> Paul> of jumping to GDB's collector function we would execute the code
> Paul> compiled by GCC each time we hit the selected instruction.
>
> I am not sure I really understand the idea.
>
> With the "compile" command, we had hopes of someday extending it to
> either allow fast breakpoint conditions (by compiling the breakpoint
> condition and patching the process); or to allow fix-and-continue
> (recompiling a single function and inserting it).
>
> Is your idea like one of these?  If it's different, could you maybe show
> an example of how a user would use it?
>
> Paul>    -  Has someone already worked on this ? On the wiki page there are
> Paul> mentions to future projects that seem related (fast breakpoint
> Paul> conditions most notably)
>
> As far as I know nobody is working on it.
>
> Paul>    -  Do you see any reason why that would not work that I missed,
> Paul> except for the limitations of the existing Compile project?
>
> I think it's entirely possible.  I think the main issues involve the
> patching -- figuring out how to replace instructions.  Maybe dyninst
> could be used to help with the rewriting, or maybe it can be done purely
> in gdb.
>
> thanks,
> Tom



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

end of thread, other threads:[~2018-12-17 17:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 16:09 [Compile] Inserting compiled code via jumps Paul Naert
2018-12-15 22:54 ` Tom Tromey
2018-12-17 17:01   ` Paul Naert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).