From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29358 invoked by alias); 5 Jul 2010 18:50:32 -0000 Received: (qmail 29347 invoked by uid 22791); 5 Jul 2010 18:50:31 -0000 X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL,BAYES_50,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM X-Spam-Check-By: sourceware.org Received: from mail-gx0-f169.google.com (HELO mail-gx0-f169.google.com) (209.85.161.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Jul 2010 18:50:26 +0000 Received: by gxk4 with SMTP id 4so2078539gxk.0 for ; Mon, 05 Jul 2010 11:50:24 -0700 (PDT) Received: by 10.101.147.19 with SMTP id z19mr4201758ann.66.1278355824524; Mon, 05 Jul 2010 11:50:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.19.10 with HTTP; Mon, 5 Jul 2010 11:50:04 -0700 (PDT) In-Reply-To: <4A25DE879BC24E8DAEAEBD722E363025@igor> References: <4A25DE879BC24E8DAEAEBD722E363025@igor> From: =?UTF-8?B?UGV0ciBIbHV6w61u?= Date: Mon, 05 Jul 2010 18:50:00 -0000 Message-ID: Subject: Re: Examining copied stack contents To: =?UTF-8?Q?Martin_Schr=C3=B6der?= Cc: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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-07/txt/msg00011.txt.bz2 Hello Martin and list On 3 July 2010 12:46, Martin Schr=C3=B6der wrote: > Hello everyone. > > I'm currently implementing a high-level debugger based on GDB for a > coroutine-based simulation framework. The platform is GNU/Linux on x86. > > That framework implements coroutines by using the C/C++ setjmp/longjmp > instructions and by copying the call stack that is used by each coroutine= to > dynamically allocated memory on the heap. It's this latter aspect that gi= ves > me terrible headaches in GDB. > > My question is simply: Is it possible to point GDB to the copied contents= of > the call stack and tell it to print out the information contained therein? (Note I am not familiar in x86 stack-walking stuff.) In general a debugger needs at least a stack pointer and an instruction pointer to get a backtrace. If the function containing the IP uses a frame pointer (a debugger should be able to tell you that) then debugger needs to know the FP. Which register contains the FP depends on the prologue type chosen by compiler (on x86 it is always EBP). Command "info frame
" may assume IP is pointed to by SP. So there are at least 2 arguments (FP+SP) to be provided on any arch. Therefore I suspect "info frame
" is not general enough to be used in your case. > That framework implements coroutines by using the C/C++ setjmp/longjmp > instructions and by copying the call stack that is used by each coroutine= to > dynamically allocated memory on the heap. Beware that a function compiled without -fomit-frame-pointer saves SP to stack and gdb uses the value to obtain stack-trace (this is not quite exact). If you copy a stack somewhere and use gdb to walk the stack there then gdb will try to use SP values pointing to the "old" stack memory. (And you cannot resume execution of the stack while in the new memory.) > But I'm also aware that the GDB *should be* able to do what I want it to = do. > For one, the documentation explicitly mentions that the feature works with > programs that utilize multiple stacks. Furthermore, the GDB is also able = to > debug Multi-Threaded programs, which also need to save the call stack to > dynamic heap memory. When doing multithreaded programs gdb gets register values from pthread library (or linux kernel?) or by remote target command. And the stack frames stay where they were created - they are not copied. > So, my question is: Is it possible to examine the copied stack? And if ye= s, > what do I need to give to the GDB to allow it? I do not know. Someone else have to answer that. --=20 Petr Hluzin