1

As mentioned in this question, I want to skip over all std functions when stepping. Making skip -rfu "std::.*" sort of works but sometimes it's too crude.

Let's say I have a code like this:

auto p = std::make_shared<Something>(yadda yadda); 

When skip is enabled, step will just step over this entire line even if ctor of Something is non-trivial. The same issue arises when I try to step into call of std::function instance.

Is it possible to skip only std, not entire callchain if there is something from std in it?

Amomum
  • 6,217
  • 8
  • 34
  • 62

2 Answers2

0

Is it possible to skip only std, not entire callchain if there is something from std in it?

Not efficiently.

Think about what it would take to implement this. You would have to single-step one instruction at a time, and look at the function name at each instruction to decide whether it's one that should be skipped or not.

C++11 lambdas which can be inlined could make this worse -- a lambda could be inlined into an std::... function, but arguably shouldn't match std::.*.

So could this be made to work? -- probably.

Will it be actually useful? -- probably only very rarely.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
0

This answer suggests using python scripting ability for gdb. So I managed to construct this a bit messy script that works for me most of the time (although sometimes it requires a step or two to step out of ASAN assembly):

import gdb
import re

def stop_handler(event):
    frame_name = gdb.selected_frame().name()
    if re.search("(^std::.*)|(^boost::.*)|(^__gnu_cxx::.*)|(^__sanitizer::.*)|(^__ubsan::.*)", frame_name) != None:
        gdb.execute("step")
        return
    
    symtab = gdb.selected_frame().find_sal().symtab
    fullname = symtab.fullname()

    matches = ["libsanitizer", "sysdeps", "/usr/include/", "ubsan"]
    if any(x in fullname for x in matches):
        gdb.execute("step")
        return

    objfile = symtab.objfile.filename

    if "libubsan.so" in objfile:
        gdb.execute("step")
        return

gdb.events.stop.connect(stop_handler)   

I'm using Clion and this script makes it blink really fast while stepping through files, so I guess be aware of a blinking hazard

Amomum
  • 6,217
  • 8
  • 34
  • 62