Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Debugging classes.
@ 2010-10-01 18:07 John Coppens
  2010-10-01 19:28 ` John Coppens
  0 siblings, 1 reply; 2+ messages in thread
From: John Coppens @ 2010-10-01 18:07 UTC (permalink / raw)
  To: gdb

Hello people.

I'm getting the following error message in places I wouldn't expect it. 
I don't know if this is a gdb bug (I've seen some messages about similar
problems), or a programming error of mine:

Cannot access memory at address 0xb7

Gdb version is 7.1, distro is Slackware 13.1 (updated).

This is the sequence of events leading to the error:

1) in a main program, I declared an instance of class SingleStep:

  SingleStep stepper;

2) I set a breakpoint inside method ::step, start the program, and
get to the breakpoint:

Breakpoint 1, SingleStep::step (this=0x6067e0, mem=0x607030,
pc=0x7fffffffdcdc) at step.cpp:670 670	  switch (opcode[opc_line].operation) {

(gdb) p this
$1 = (SingleStep * const) 0x6067e0

(All as expected)

3) After a few loops ('this' is still the same), I enter into a call from the 
same class:

689	    case OP_JGE:	do_jump_if(mem, pc, opc, !(get_SR_bit(SR_N) ^ get_SR_bit(SR_V))); break;
(gdb) s
SingleStep::get_SR_bit (this=0x6067e0, mem=0x607030, pc=0x7fffffffdcdc) at step.cpp:716
716	  return (r[REG_SR] & (1 << bit)) != 0;
(gdb) p this
$2 = (SingleStep * const) 0xf

Why is SingleStep suddenly 0xf? Of course, I can't access internal variables
with this value:

(gdb) p r
Cannot access memory at address 0x67
(gdb) p this->r
Cannot access memory at address 0x67

I'd appreciate suggestions here!

John

BTW: the get_SR_bit method called is:

int
SingleStep::get_SR_bit(int bit)
{
  return (r[REG_SR] & (1 << bit)) != 0;
}

It is declared as a private method of SingleStep.


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

* Re: Debugging classes.
  2010-10-01 18:07 Debugging classes John Coppens
@ 2010-10-01 19:28 ` John Coppens
  0 siblings, 0 replies; 2+ messages in thread
From: John Coppens @ 2010-10-01 19:28 UTC (permalink / raw)
  To: gdb

On Fri, 1 Oct 2010 15:07:05 -0300
John Coppens <john@jcoppens.com> wrote:

> Cannot access memory at address 0xb7
> 

Gdb has problems visualizing values with optimizing on (-O2 in my
case). Solutions:

- Switch optimizing off, or
- Use a previous 'this', when it was still valid

Thanks to the #gdb IRC channel, I received suggestions that gdb 4.5.x
has some of these problems solved.

Cheers,
John


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

end of thread, other threads:[~2010-10-01 19:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-01 18:07 Debugging classes John Coppens
2010-10-01 19:28 ` John Coppens

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