ASSERT unix/os.c:4058 num_fd_add_pre_heap == 1 && "only main_logfile should come here"
I'm adding a new drcachesim analysis tool (#4083 (closed)) and I hit an assert that I believe opcode_mix should hit too:
$ bin64/drrun -t drcachesim -simulator_type func_view -record_heap -record_function memcpy\|10\|3\&memset\|11\|3 -indir drmemtrace.cs2bug.63574.1050.dir/
<Application /home/bruening/dr/git/build_x64_dbg_tests/clients/bin64/drcachesim (63986). Internal Error: DynamoRIO debug check failure: /home/bruening/dr/git/src/core/unix/os.c:4058 num_fd_add_pre_heap == 1 && "only main_logfile should come here"
(Error occurred @-1 frags)
Not happening for other tools b/c just one instance so the count is 1.
Breakpoint 1, os_open_protected (fname=0x555555770970 "drmemtrace.cs2bug.63574.1050.dir//raw/modules.log", os_open_flags=1)
at /home/bruening/dr/git/src/core/unix/os.c:4084
4084 file_t res = os_open(fname, os_open_flags);
(gdb) bt
#0 os_open_protected (fname=0x555555770970 "drmemtrace.cs2bug.63574.1050.dir//raw/modules.log", os_open_flags=1)
at /home/bruening/dr/git/src/core/unix/os.c:4084
#1 0x00007ffff7ad150e in dr_open_file (fname=0x555555770970 "drmemtrace.cs2bug.63574.1050.dir//raw/modules.log", mode_flags=1)
at /home/bruening/dr/git/src/core/lib/instrument.c:4260
#2 0x000055555562a928 in raw2trace_directory_t::read_module_file (this=0x5555557789a8, modfilename="drmemtrace.cs2bug.63574.1050.dir//raw/modules.log")
at /home/bruening/dr/git/src/clients/drcachesim/tracer/raw2trace_directory.cpp:156
#3 0x000055555562b3f1 in raw2trace_directory_t::initialize_module_file (this=0x5555557789a8,
module_file_path="drmemtrace.cs2bug.63574.1050.dir//raw/modules.log") at /home/bruening/dr/git/src/clients/drcachesim/tracer/raw2trace_directory.cpp:244
#4 0x000055555560f5ef in func_view_t::initialize[abi:cxx11]() (this=0x5555557788f0) at /home/bruening/dr/git/src/clients/drcachesim/tools/func_view.cpp:81
#5 0x00005555555ad7ce in analyzer_multi_t::create_analysis_tools (this=0x5555557707f0) at /home/bruening/dr/git/src/clients/drcachesim/analyzer_multi.cpp:165
#6 0x00005555555acba0 in analyzer_multi_t::analyzer_multi_t (this=0x5555557707f0) at /home/bruening/dr/git/src/clients/drcachesim/analyzer_multi.cpp:61
#7 0x000055555559a1c6 in main (argc=16, targv=0x7fffffffdbd8) at /home/bruening/dr/git/src/clients/drcachesim/launcher.cpp:284
(gdb) c
Continuing.
os_open_protected drmemtrace.cs2bug.63574.1050.dir//raw/modules.log
Breakpoint 1, os_open_protected (fname=0x55555577b040 "drmemtrace.cs2bug.63574.1050.dir/raw/modules.log", os_open_flags=1)
at /home/bruening/dr/git/src/core/unix/os.c:4084
4084 file_t res = os_open(fname, os_open_flags);
(gdb) bt
#0 os_open_protected (fname=0x55555577b040 "drmemtrace.cs2bug.63574.1050.dir/raw/modules.log", os_open_flags=1)
at /home/bruening/dr/git/src/core/unix/os.c:4084
#1 0x00007ffff7ad150e in dr_open_file (fname=0x55555577b040 "drmemtrace.cs2bug.63574.1050.dir/raw/modules.log", mode_flags=1)
at /home/bruening/dr/git/src/core/lib/instrument.c:4260
#2 0x000055555562a928 in raw2trace_directory_t::read_module_file (this=0x7fffffffcf90, modfilename="drmemtrace.cs2bug.63574.1050.dir/raw/modules.log")
at /home/bruening/dr/git/src/clients/drcachesim/tracer/raw2trace_directory.cpp:156
#3 0x000055555562b2dd in raw2trace_directory_t::initialize (this=0x7fffffffcf90, indir="drmemtrace.cs2bug.63574.1050.dir/", outdir="")
at /home/bruening/dr/git/src/clients/drcachesim/tracer/raw2trace_directory.cpp:236
#4 0x00005555555acfbc in analyzer_multi_t::analyzer_multi_t (this=0x5555557707f0) at /home/bruening/dr/git/src/clients/drcachesim/analyzer_multi.cpp:104
#5 0x000055555559a1c6 in main (argc=16, targv=0x7fffffffdbd8) at /home/bruening/dr/git/src/clients/drcachesim/launcher.cpp:284
(gdb) p standalone_library
$1 = false
Hmm so standalone_library is not set for drcachesim. So frontendlib and injectlib don't set it. I guess they just don't use any routines that need init. But what about launcher.cpp including dr_api?
Definitely raw2trace_directory.cpp calling dr_open_file: it should call dr_standalone_init() first. But first: why does raw2trace take in a dcontext and avoid calling standalone_init? B/c we didn't support multiple calls back then? Or do we have some use case that does not want to be standalone b/c it's full DR?
Seems like we want a negative condition: !managed_mode or sthg, and we set that when we take over. Or, could have standalone_library be true by default?
My plan is to put handling of multiple calls to the new dr_standalone_exit(), and add standalone init and exit calls to raw2trace_directory, and add a missing exit call to raw2trace.