public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Re: Debug code in data section in gdb
@ 2004-06-22 23:17 Michael Elizabeth Chastain
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Elizabeth Chastain @ 2004-06-22 23:17 UTC (permalink / raw)
  To: mec.gnu, zhangtao; +Cc: gdb

> I can break the program just before the execution jump to the
> code copied from somewhere. Then I set a breakpoint at the beginning of
> the copied code. It still won't work.

That's the right thing to do.  It should work.

> Another thing is I see the code is same as the original code. My
> question is whether I can see the GDB modified instruction by
> disassemble the memory ? When and How gdb modifies the instruction?

gdb goes to some lengths to report the original contents of memory
no matter how you examine it.

> I suspect this problem is specific to my port of gdb, so maybe I need to
> understand how breakpoints work in gdb to understand my problem. Could
> anybody give me some pointers to articles or online books on debugger or
> gdb?

Mmmm, start with the gdb internals manual (doc/gdbint.texinfo).

Again, it would help a lot if you could use the 'script' command to
capture an entire gdb session, and then mail in the 'typescript' file.

Michael C

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

* Re: Debug code in data section in gdb
  2004-06-22 22:23 ` Tao Zhang
@ 2004-06-23  5:03   ` Jim Blandy
  0 siblings, 0 replies; 9+ messages in thread
From: Jim Blandy @ 2004-06-23  5:03 UTC (permalink / raw)
  To: Tao Zhang; +Cc: Michael Elizabeth Chastain, gdb


Tao Zhang <zhangtao@cc.gatech.edu> writes:
> Yeah, I understand GDB will modify the code at the address of a
> breakpoint. I can break the program just before the execution jump to the
> code copied from somewhere. Then I set a breakpoint at the beginning of
> the copied code. It still won't work. Another thing is I see the code is
> same as the original code. My question is whether I can see the GDB modified
> instruction by disassemble the memory ? When and How gdb modifies the
> instruction?

GDB inserts breakpoints just before resuming the inferior (debuggee)
and removes them all each time the inferior stops.  When you
disassemble, the inferior is stopped, so you won't see GDB's
breakpoint.

You said your inferior was running "without an OS", so I assume you're
communicating with it via the GDB remote protocol.  Have you tried
"set debug remote 1" to see exactly what GDB and your inferior are
saying to each other?  In particular, you should be able to see GDB
writing the breakpoint instruction, after reading the original
contents, and then restoring the original contents when the inferior
stops.

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

* Re: Debug code in data section in gdb
  2004-06-22 22:09 Michael Elizabeth Chastain
@ 2004-06-22 22:23 ` Tao Zhang
  2004-06-23  5:03   ` Jim Blandy
  0 siblings, 1 reply; 9+ messages in thread
From: Tao Zhang @ 2004-06-22 22:23 UTC (permalink / raw)
  To: Michael Elizabeth Chastain; +Cc: gdb

Hi, Michael

Yeah, I understand GDB will modify the code at the address of a
breakpoint. I can break the program just before the execution jump to the
code copied from somewhere. Then I set a breakpoint at the beginning of
the copied code. It still won't work. Another thing is I see the code is
same as the original code. My question is whether I can see the GDB modified
instruction by disassemble the memory ? When and How gdb modifies the
instruction?

I suspect this problem is specific to my port of gdb, so maybe I need to
understand how breakpoints work in gdb to understand my problem. Could
anybody give me some pointers to articles or online books on debugger or
gdb?

Thanks so much

Tao


			-Tao Zhang (zhangtao@cc.gatech.edu)

On Tue, 22 Jun 2004, Michael Elizabeth Chastain wrote:

> Hi Tao,
>
> It sounds like, perhaps, you are placing the breakpoint first,
> and then copying the code on top of the location of the breakpoint.
>
> The way gdb sets breakpoints (usually) is that gdb writes a BREAKPOINT
> instruction into the memory at the address indicated.  So if you
> set a breakpoint first, then overwrite that memory with your own
> contents, then you will overwrite the BREAKPOINT instruction and
> lose it.
>
> Can you capture a complete gdb session with the 'script' command
> and mail it in?
>
> Michael C
> GDB QA Guy
>

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

* Re: Debug code in data section in gdb
  2004-06-22 20:43   ` Andreas Schwab
@ 2004-06-22 22:14     ` Tao Zhang
  0 siblings, 0 replies; 9+ messages in thread
From: Tao Zhang @ 2004-06-22 22:14 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Michael Elizabeth Chastain, gdb

"doesn't work" means the execution doens't stop at the break points...


			-Tao Zhang (zhangtao@cc.gatech.edu)

On Tue, 22 Jun 2004, Andreas Schwab wrote:

> Tao Zhang <zhangtao@cc.gatech.edu> writes:
>
> > Hi, Michael
> >
> > I tried that many times, it doesn't work for me. I even played some trick
> > so that the code buffer is actually placed in code section now. It still
> > doesn't work. I am very confused. The breakpoints work just fine for other
> > code.
>
> Please define "doesn't work".  What are the symptoms?
>
> > So break *0x12344657 should work?
>
> Yes.  GDB does not distinguish between "code" and "data" section when
> placing a breakpoint, it's all just memory.
>
> Andreas.
>
> --
> Andreas Schwab, SuSE Labs, schwab@suse.de
> SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
> Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>

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

* Re: Debug code in data section in gdb
@ 2004-06-22 22:09 Michael Elizabeth Chastain
  2004-06-22 22:23 ` Tao Zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Elizabeth Chastain @ 2004-06-22 22:09 UTC (permalink / raw)
  To: mec.gnu, zhangtao; +Cc: gdb

Hi Tao,

It sounds like, perhaps, you are placing the breakpoint first,
and then copying the code on top of the location of the breakpoint.

The way gdb sets breakpoints (usually) is that gdb writes a BREAKPOINT
instruction into the memory at the address indicated.  So if you
set a breakpoint first, then overwrite that memory with your own
contents, then you will overwrite the BREAKPOINT instruction and
lose it.

Can you capture a complete gdb session with the 'script' command
and mail it in?

Michael C
GDB QA Guy

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

* Re: Debug code in data section in gdb
  2004-06-22 19:10 ` Tao Zhang
@ 2004-06-22 20:43   ` Andreas Schwab
  2004-06-22 22:14     ` Tao Zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2004-06-22 20:43 UTC (permalink / raw)
  To: Tao Zhang; +Cc: Michael Elizabeth Chastain, gdb

Tao Zhang <zhangtao@cc.gatech.edu> writes:

> Hi, Michael
>
> I tried that many times, it doesn't work for me. I even played some trick
> so that the code buffer is actually placed in code section now. It still
> doesn't work. I am very confused. The breakpoints work just fine for other
> code.

Please define "doesn't work".  What are the symptoms?

> So break *0x12344657 should work?

Yes.  GDB does not distinguish between "code" and "data" section when
placing a breakpoint, it's all just memory.

Andreas.

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

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

* Re: Debug code in data section in gdb
  2004-06-22 18:19 Michael Elizabeth Chastain
@ 2004-06-22 19:10 ` Tao Zhang
  2004-06-22 20:43   ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Tao Zhang @ 2004-06-22 19:10 UTC (permalink / raw)
  To: Michael Elizabeth Chastain; +Cc: gdb

Hi, Michael

I tried that many times, it doesn't work for me. I even played some trick
so that the code buffer is actually placed in code section now. It still
doesn't work. I am very confused. The breakpoints work just fine for other
code.

So break *0x12344657 should work? Then maybe it is the problem of my gdb
port rather than general gdb?

Thanks a lot


Tao


			-Tao Zhang (zhangtao@cc.gatech.edu)

On Tue, 22 Jun 2004, Michael Elizabeth Chastain wrote:

> > Is there a way to ask gdb to set break points at data section?
> > Or is there some other work around?
>
> If you know the exact address where you want to set the breakpoint,
> you can do:
>
>   (gdb) break *0x12345678
>
> Be sure to do this after you've copied your code into the data
> section, not before.
>
> Michael C
>

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

* Re: Debug code in data section in gdb
@ 2004-06-22 18:19 Michael Elizabeth Chastain
  2004-06-22 19:10 ` Tao Zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Elizabeth Chastain @ 2004-06-22 18:19 UTC (permalink / raw)
  To: gdb, zhangtao

> Is there a way to ask gdb to set break points at data section?
> Or is there some other work around?

If you know the exact address where you want to set the breakpoint,
you can do:

  (gdb) break *0x12345678

Be sure to do this after you've copied your code into the data
section, not before.

Michael C

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

* Debug code in data section in gdb
@ 2004-06-22 17:36 Tao Zhang
  0 siblings, 0 replies; 9+ messages in thread
From: Tao Zhang @ 2004-06-22 17:36 UTC (permalink / raw)
  To: gdb

Hi,

I have to copy a piece of code to a buffer in data section then execute
the code. I need to debug the code in the buffer to capture the problem
due to the copying of the code. I tried to use gdb to set breakpoints in
the code buffer (in data section) but it doesn't work. There is no OS at all,
so OS won't prevent the execution of something in data section. Is there a
way to ask gdb to set break points at data section? Or is there some other
work around?

Thanks so much


Tao


			-Tao Zhang (zhangtao@cc.gatech.edu)

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

end of thread, other threads:[~2004-06-23  5:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-22 23:17 Debug code in data section in gdb Michael Elizabeth Chastain
  -- strict thread matches above, loose matches on Subject: below --
2004-06-22 22:09 Michael Elizabeth Chastain
2004-06-22 22:23 ` Tao Zhang
2004-06-23  5:03   ` Jim Blandy
2004-06-22 18:19 Michael Elizabeth Chastain
2004-06-22 19:10 ` Tao Zhang
2004-06-22 20:43   ` Andreas Schwab
2004-06-22 22:14     ` Tao Zhang
2004-06-22 17:36 Tao Zhang

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).