Skip to content

Conversation

@NicksWorld
Copy link
Contributor

This PR adds functionality to DFHack that enables it to produce crashlogs (on Linux only) upon the majority of crashes (specifically ignoring those that occur post-shutdown).

There are a few topics I wish to address before considering it ready:

  • BT_ENTRY_MAX can be any arbitrary value, is 25 lines a good limit, or should it be higher?
  • Should this feature be togglable with an environment variable?
  • A review of concurrency, as the implementation makes use of quite a few atomics and filedescriptors in an attempt to maintain async-signal safety in the signal handler. It passes the trials I've put it through, but there may be more edge cases.

As the implementation stands, I think the only possible hang would be if file io stalled whilst writing the crashlog. The crashlogs include a header that aims to make it clear these logs are produced by dfhack and not the vanilla game, which should hopefully prevent confusion.

An example generated crashlog is as follows:

Dwarf Fortress Linux has crashed!
Dwarf Fortress Version 53.03
DFHack Version 53.03-r1

Signal SIGSEGV
0> hack/libdfhack-debug.so(+0xc669da) [0x7fffe38669da]
1> /usr/lib/libc.so.6(+0x3e540) [0x7ffff6e3e540]
2> hack/libdfhack-debug.so(_ZN6DFHack16pointer_identity8lua_readEP9lua_StateiPvPKNS_13type_identityE+0x1b) [0x7fffe34301c1]
3> hack/libdfhack-debug.so(+0x83127c) [0x7fffe343127c]
4> hack/libdfhack-debug.so(+0x831749) [0x7fffe3431749]
5> hack/liblua53.so(+0x18769) [0x7fffe3f4c769]
6> hack/liblua53.so(+0x18afb) [0x7fffe3f4cafb]
7> hack/liblua53.so(+0x18b6e) [0x7fffe3f4cb6e]
8> hack/liblua53.so(+0x33b20) [0x7fffe3f67b20]
9> hack/liblua53.so(+0x35ceb) [0x7fffe3f69ceb]
10> hack/liblua53.so(_Z12lua_gettableP9lua_Statei+0xe3) [0x7fffe3f3ea8e]
11> hack/libdfhack-debug.so(+0x831bee) [0x7fffe3431bee]
12> hack/liblua53.so(+0x18769) [0x7fffe3f4c769]
13> hack/liblua53.so(+0x18afb) [0x7fffe3f4cafb]
14> hack/liblua53.so(+0x3b9e3) [0x7fffe3f6f9e3]
15> hack/liblua53.so(+0x18b10) [0x7fffe3f4cb10]
16> hack/liblua53.so(+0x18b6e) [0x7fffe3f4cb6e]
17> hack/liblua53.so(_Z9lua_callkP9lua_StateiilPFiS0_ilE+0xb5) [0x7fffe3f3fd62]
18> hack/libdfhack-debug.so(_ZN6DFHack21dfhack_lua_viewscreen8do_inputEP9lua_State+0x139) [0x7fffe38348d7]
19> hack/liblua53.so(+0x18769) [0x7fffe3f4c769]
20> hack/liblua53.so(+0x18afb) [0x7fffe3f4cafb]
21> hack/liblua53.so(+0x18b6e) [0x7fffe3f4cb6e]
22> hack/liblua53.so(+0xbde0) [0x7fffe3f3fde0]
23> hack/liblua53.so(+0x17a81) [0x7fffe3f4ba81]
24> hack/liblua53.so(+0x1942e) [0x7fffe3f4d42e]

@NicksWorld NicksWorld marked this pull request as ready for review November 15, 2025 02:49
@ab9rf ab9rf merged commit b4d6e82 into DFHack:develop Nov 16, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants