0

In gdb, is there a way to step into only the outermost function? Often times I step into a function, there are many constructors that I end up stepping into due to many of the object arguments in the function being initialized. I'll have to step in and out multiple times until I get to the actual function I want to step into. Is there a quick way to step into what essentially would be the outermost function?

  • I suppose a workaround could be to write a gdb function that would finish the current function and step again into the new function. It doesn't really solve the problem, but at least I would only need one command (the call to the gdb function) to finish the function and jump into the next function rather than manually using two commands (finishing, then stepping again). – John Demetros Feb 04 '22 at 14:07
  • "step" means "step into" while "next" means execute a line of code without going into it. What is your problem to use "next" instead of "step"? And "until" runs until curent scope is left which is perfect if you already stepped inside a function you simply want to leave. – Klaus Feb 04 '22 at 14:11
  • @HansOlsson Based on that post there is no solution. But I'm still hoping there is one. – John Demetros Feb 04 '22 at 14:13
  • @Klaus "next" will skip over all functions that I'm on, which is not what I want. I want to skip all functions but the outermost one. And I haven't used "until" but it looks like for my purposes, it would just be the same as finishing the current function. – John Demetros Feb 04 '22 at 14:16
  • I can't catch your problem! Use step if you want go into and next if not. You are sitting upfront your pc. Or do you want to write an automated script which must know the depth of the stack or what is the underlying problem? If you want to go one level deeper use step, next next next... until and step again... no idea what you really want ro solve! – Klaus Feb 04 '22 at 14:19
  • If you have used "Step Into Specific Function" in Visual Studio in C++-code (especially with lots of implicit conversions) you can see this problem. – Hans Olsson Feb 04 '22 at 14:29
  • @Klaus Write a function that accepts 3 parameters of type `std::string`. Call this function with three C-style string arguments. Try to step into that function with gdb. Report back how many gdb commands it took. – n. m. could be an AI Feb 04 '22 at 14:31
  • @n.1.8e9-where's-my-sharem. The [`skip`](https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html) command works for me if I want to ignore `std::string` constructors when stepping. – ssbssa Feb 04 '22 at 15:52
  • @Klaus I am dealing with functions that have many constructors being called from the arguments, sometimes as much as 6. If I hit next, I'll skip over all the functions. I want to skip over all of the constructors and go directly to the outermost function of the line I am currently on. Normally I will step into the construction, finish the constructor, step into the next constructor, finish the constructor, etc... until I finally have gone through all the constructors and now I'm in the function I want to be on. Not sure why this is difficult to understand. – John Demetros Feb 04 '22 at 16:28
  • @HansOlsson Unfortunately I don't have Visual Studio, but perhaps I can write a gdb function that will set a temporary break point on the current function I'm on, and then when I hit next, I'll enter only that function. I mean even doing this manually is fine, considering it's two commands; it's just that sometimes I don't know how many constructors I have to go through. Sometimes it's zero, other times is 6 or even 7. And I'm just looking for a 1 line gdb command. – John Demetros Feb 04 '22 at 16:31
  • I don't know why this question was closed as a duplicate of https://stackoverflow.com/questions/11967440/stepping-into-specific-function-in-gdb. If I have a function with 10 or so arguments, I'm supposed to know which of these arguments are objects of which the constructor is going to be called, so that I can skip them?? This will take more time than just stepping and finishing repeatedly.... – John Demetros Feb 04 '22 at 16:48
  • @ssbssa Yes, if you want to skip all `std` functions, `skip` is the way to go. Although sometimes it is too much, e.g. you cannot skip the `std::invoke` boilerplate and go straight to your function this way. If you want to skip only non-top-level function calls only for the current statement, it is not useful. Use `advance` in this case. – n. m. could be an AI Feb 04 '22 at 17:18
  • 1
    @JohnDemetros use `advance `. This advice is in the duplicate answer. Also, a separate piece of advice: if you want to skip e.g. functions in `namespace std`, use `skip -rfu ^std::` – n. m. could be an AI Feb 04 '22 at 17:22
  • OK, so the question is not how to step into and over, but ignoring code which was written from you ( in a short ). That is not my understanding of "outermost" code at all. To ignore code which comes from different source locations like boost/stl/qt or whatever, it is possible to write a little python script. And yes, this is not mentioned in the duplicate! But you get an idea here: https://stackoverflow.com/questions/5676241/tell-gdb-to-skip-standard-files – Klaus Feb 04 '22 at 18:06

0 Answers0