intro

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid
[1]    441709 IOT instruction  build/ccshell

It’s so annoying that you don’t have any information regarding what’s wrong

It’s usually a bad idea to binary search by adding print statements because it’s slow (log time), but gdb is instant

compile options

-O0 OPTFLAGS += -ggdb3 -fno-omit-frame-pointer -fno-inline -D_GLIBCXX_ASSERTIONS

gdb

First run the program

$ gdb --args build/ccshell
gdb> catch throw
gdb> run

When the program stops, check the status

gdb> bt
#0  0x00007ffff7cbd961 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x00007ffff7cadb58 in std::__throw_logic_error(char const*) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x000055555555c770 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> > (this=0x7ffffffdcd80, __s=0x0, __a=...)
    at /usr/include/c++/14/bits/basic_string.h:651
#3  0x000055555557f80d in ov4::find_cmd[abi:cxx11](char const*) (s=0x0) at src/path.cc:10
#4  0x000055555557d072 in ov4::eval_exe (s="ls", is_aync=0x0) at src/eval.cc:54
#5  0x000055555557d5a4 in ov4::eval_tree_cd (i=0x1, lexer_instance=...) at src/eval.cc:130
#6  0x000055555557d5fd in ov4::eval_tree_cd (i=0x0, lexer_instance=...) at src/eval.cc:135
#7  0x000055555557d721 in ov4::eval (cmdline=0x7fffffffd8f0 "ls && ls\n") at src/eval.cc:172
#8  0x000055555557c9b2 in main (argc=0x1, argv=0x7fffffffde08) at src/main.cc:79

We can find the smallest index beloning to our program (standard lib is never wrong!)

H.ere it’s ov4::find_cmd[abi:cxx11](char const*) (s=0x0) at src/path.cc:10 Then just check the corresponding src file