From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20596 invoked by alias); 1 Oct 2010 18:07:20 -0000 Received: (qmail 20578 invoked by uid 22791); 1 Oct 2010 18:07:19 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU X-Spam-Check-By: sourceware.org Received: from caiajhbdcbbj.dreamhost.com (HELO homiemail-a7.g.dreamhost.com) (208.97.132.119) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Oct 2010 18:07:15 +0000 Received: from homiemail-a7.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a7.g.dreamhost.com (Postfix) with ESMTP id AC34B25C06E for ; Fri, 1 Oct 2010 11:07:13 -0700 (PDT) Received: from on6jc.ampr.net (host180.190-136-57.telecom.net.ar [190.136.57.180]) (Authenticated sender: john@jcoppens.com) by homiemail-a7.g.dreamhost.com (Postfix) with ESMTPA id D0D4925C06B for ; Fri, 1 Oct 2010 11:07:12 -0700 (PDT) Date: Fri, 01 Oct 2010 18:07:00 -0000 From: John Coppens To: gdb@sourceware.org Subject: Debugging classes. Message-Id: <20101001150705.ab95907e.john@jcoppens.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00001.txt.bz2 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.