This is the mail archive of the
mailing list for the GCC project.
Re: how to tweak x86 code generation to instrument certain opcodes with CC trap?
- From: Yasser Shalabi <yassershalabi at gmail dot com>
- To: William Cohen <wcohen at redhat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 26 Oct 2015 14:47:29 -0500
- Subject: Re: how to tweak x86 code generation to instrument certain opcodes with CC trap?
- Authentication-results: sourceware.org; auth=none
- References: <CACkfA5s-k4kP7hM6FarVMEc-eREn2pGwQr+=sVsf3LRaxjG_ug at mail dot gmail dot com> <562A5309 dot 8060302 at redhat dot com> <CACkfA5tS=+YNRi1fk6UoJe_zeGoDOEJ7FttZBLEektTUL2HC0w at mail dot gmail dot com> <562A55BE dot 7080700 at redhat dot com>
So I tried Dyninst but it is not as clean as I need. I am afraid I
will need to implement this in the compiler. I have already
implemented it as a backend pass for another compiler, but
unfortunately it doesnt compile the linux kernel :P
So back to square one. Any tips on what code/config-files I need to
modify with to get GCC to emit additional opcodes for certain
On Fri, Oct 23, 2015 at 10:43 AM, William Cohen <email@example.com> wrote:
> On 10/23/2015 11:37 AM, Yasser Shalabi wrote:
>> Hey Will,
>> Thanks for the quick reply. Yeah I need the int3 instruction to be
>> statically included in he binary so I can't use any dynamic
>> instrumentation tool.
> Dyninst can do binary rewrites of executables so that might still be suitable.
>> On Fri, Oct 23, 2015 at 10:32 AM, William Cohen <firstname.lastname@example.org> wrote:
>>> On 10/23/2015 01:37 AM, Yasser Shalabi wrote:
>>>> I am new to the GCC code. I want to make a simple modification to the
>>>> back end. I want to add a debug exception (int3) to be generated
>>>> before any instance of certain x86 instructions.
>>>> I tried to modify gcc/config/i386/i386.md by adding a "int3" to the
>>>> define_insn for instructions of interest. But that just caused
>>>> configure to fail (cannot run generated C programs).
>>>> Any pointers on how to approach this? Also, suggestions for
>>>> alternative approaches are also welcome.
>>> Do you need the int3 specifically before those instructions? Or are you just looking to instrument the code and collect some information before those instructions are executed? Some alternative instrumentation tools you might look at to instrument existing code are:
>>> dyninst http://www.dyninst.org/
>>> Valgrind http://valgrind.org/
>>> Intel's Pin tool https://software.intel.com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool