From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15028 invoked by alias); 3 Nov 2009 17:22:25 -0000 Received: (qmail 15019 invoked by uid 22791); 3 Nov 2009 17:22:24 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-vw0-f182.google.com (HELO mail-vw0-f182.google.com) (209.85.212.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 03 Nov 2009 17:22:20 +0000 Received: by vws12 with SMTP id 12so1820376vws.12 for ; Tue, 03 Nov 2009 09:22:18 -0800 (PST) MIME-Version: 1.0 Received: by 10.220.122.90 with SMTP id k26mr276297vcr.69.1257268938392; Tue, 03 Nov 2009 09:22:18 -0800 (PST) In-Reply-To: <4AEF6834.1080208@caviumnetworks.com> References: <4AEF6834.1080208@caviumnetworks.com> Date: Tue, 03 Nov 2009 17:22:00 -0000 Message-ID: Subject: Re: GDB interactions with GCC From: Jean Christophe Beyler To: David Daney Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2009-11/txt/msg00024.txt.bz2 > That is an simplified answer based on my limited knowledge of the subject. Thanks, it's a start. I am first gathering information and these seem to be like huge newbie questions, for which I apologize. Can someone explain how GDB does to remember what arguments were used in a backtrace ? Is it necessary that they all reside on the stack or does GDB copy them somewhere for later use, it the case of architectures that do not need to pass the arguments on the stack? Technically, on my architecture, if we had: int bar (int a) { return a; } int foo (int a, int b) { return a + b; } the compiler would generate for foo something like: ... add FirstInputRegister, FirstInputRegister, SecondInputRegister call bar ... Therefore, if I put a breakpoint at bar, if I look at FirstInputRegister, I would have a+b but if I backtraced to foo, how would GDB remember the values of a and b. In this case, must GCC generate something like this instead : ... store FirstInputRegister, 0(stack_pointer) store SecondInputRegister, 8(stack_pointer) #8 is just an offset, let's suppose int is 8 bytes... add FirstInputRegister, FirstInputRegister, SecondInputRegister call bar ... so that the arguments reside on the stack so that GDB can get them at a later date ? If so, doesn't that mean that if we want GDB on an architecture that does not require any stack copies, we still have to generate those uselessly (except for GDB ;-)) ? Thanks again, Jc On Mon, Nov 2, 2009 at 6:16 PM, David Daney wro= te: > Jean Christophe Beyler wrote: > [...] >> >> For example, on my architecture, the return address is passed in one >> register that the function can push on the stack if it's necessary (if >> a call happens) but not if it's a leaf function. The local variables >> are also sent via registers and therefore, potentially are never >> stored on the stack. > > This is similar to MIPS which is supported by gdb. > > [...] > >> And if someone can answer these questions: >> >> - It seems to me that GCC outputs debug information that helps GDB >> follow the course of the program: >> =A0 - With this information, is GDB able to follow where the local >> variables are kept (register or stack) depending on what the program >> is doing ? > > Usually. > >> =A0 - Does GCC need to output anything in particular to allow GDB to >> give the information of the backtrace for example? >> > > Yes. > >> In other words: >> >> - Does the ABI need to store the stack pointer for each frame in order >> for GDB to give all the backtrace, variable information? Or does GDB >> keep track of this independantly of the ABI. > > For some (many) archectures, the compiler emits debug information describ= ing > the information needed to generate a backtrace. =A0Look at .debug_frame > sections in DWARF for example. =A0Given a lack of frame meta-data, you can > have target specific code that does ad hoc stack and code examination to = try > to generate a backtrace. > > >> >> - Does GDB require that the ABI store arguments at some point on the >> stack in order to provide information about a function calls >> arguments? I would assume not because otherwise register-based ABIs >> would have to redundantly copy things on the stack for GDB use... >> > > The debug data emitted by the compiler should allow gdb to track variable > locations. =A0For most Linux systems this is specified by DWARF. > > That is an simplified answer based on my limited knowledge of the subject. > > David Daney > >