public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Maximilian Schneider <max@schneidersoft.net>, gdb@sourceware.org
Subject: Re: GDB call and p func() on embedded target
Date: Sat, 14 Aug 2021 09:05:58 -0400	[thread overview]
Message-ID: <10f7f78c-ac4d-b54f-b250-c915203c6f47@polymtl.ca> (raw)
In-Reply-To: <acb2bb8e83451c2181f6f1432cdc026262fd7a2e.camel@schneidersoft.net>

On 2021-08-14 6:28 a.m., Maximilian Schneider via Gdb wrote:
> Hello,
> 
> I am trying to call a function from withing a gdb debugging session on
> an embedded target. However gdb never returns and when i stop it
> manually the program counter is in a strange place. It appears that gdb
> is not able to catch the return, and is continuing  execution from
> before the core was halted... 
> 
> assume the function I want to call has prototype int32_t Init(void);
> 
> If I set the pc manually I can step throught the function until the
> return without a problem.
> 
> I can even set a breakpoint on Init and then use p Init(). The
> breakpoint will fire and I can step throught the code manually.
> 
> eg.
> 
> target remote localhost:3333
> monitor reset halt
> monitor reset init
> file loader.elf
> load loader.elf
> set $sp=0x20010000
> set $pc=&Init
> b Init
> p Init()
> n
> n
> n
> ...
> 
> However without the breakpoint gdb never returns.
> Is this a known problem? Is there a workaround?
> 
> Some background:
> The purpose of this entire excercise is to arrive at a tool/set of
> scripts that can be used to load and execute arbitrary code from RAM,
> to fi. manipulate external memories or run tests.
> 
> Regards,
> M

Hi Maximilian,

I don't think there would be a way to solve this other than debugging
GDB itself, stepping in the call_function_by_hand_dummy function to
understand what it does, how it sets up the dummy stack frame, what
technique it uses to put the breakpoint that should lead to the function
call being completed, etc..  And also running with "set debug infrun 1"
and possibly stepping through handle_inferior_event, to see why GDB
doesn't realize the function call isn't over.

The call_function_by_hand_dummy really lacks debug prints, making it
hard to debug when it goes wrong.  I was debugging another function call
issue the other day, and thought to myself that it would be a good time
to add some.

Also, inferior function call has a lot of arch-specific components to
it, so if you could mention the arch you are working on, it could help
narrow things down.

Simon


  reply	other threads:[~2021-08-14 13:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-14 10:28 Maximilian Schneider
2021-08-14 13:05 ` Simon Marchi [this message]
2021-08-14 15:54   ` Maximilian Schneider
2021-08-16  1:14     ` Simon Marchi
2021-08-18 20:31       ` Maximilian Schneider
2021-08-18 20:49         ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10f7f78c-ac4d-b54f-b250-c915203c6f47@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb@sourceware.org \
    --cc=max@schneidersoft.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).