Crystal: exception.backtrace? raises another exception when using exec -a

Created on 2 Dec 2019  路  3Comments  路  Source: crystal-lang/crystal

Submitting bugs

I try to print the backtrace when I rescue an exception. That will fail if I started my program with the following shell script:

#!/usr/bin/bash
exec -a "another-name" /path/to/my-program
````

Note that exec in this case is [the bash builtin command exec](https://www.computerhope.com/unix/bash/exec.htm). it  has a `-a` flag that sets the program name.

Looking at the error message below, it seems that the program is trying to open itself (using the wrong name) in order to print a backtrace.

```console
Unhandled exception: Error opening file 'another-name' with mode 'r': No such file or directory (Errno)
Failed to raise an exception: END_OF_STACK
[0x565065d4fed6] *CallStack::print_backtrace:Int32 +118
[0x565065d35589] __crystal_raise +89
[0x565065d35aa4] ???
[0x565065d69413] *Crystal::System::File::open<String, String, File::Permissions>:Int32 +211
[0x565065d65b02] *File::new<String, String, File::Permissions, Nil, Nil>:File +66
[0x565065d46c4d] *CallStack::read_dwarf_sections:(Array(Tuple(UInt64, UInt64, String)) | Nil) +109
[0x565065d469dd] *CallStack::decode_line_number<UInt64>:Tuple(String, Int32, Int32) +45
[0x565065d46176] *CallStack#decode_backtrace:Array(String) +294
[0x565065d46032] *CallStack#printable_backtrace:Array(String) +50
[0x565065d9794f] *Exception+ +79
[0x565065d977c1] *Exception+ +113
[0x565065d957bf] *AtExitHandlers::run<Int32>:Int32 +447
[0x565065da28b4] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +132
[0x565065d3ff56] main +6
[0x7f72bf564153] __libc_start_main +243
[0x565065d344de] _start +46
[0x0] ???

I made this small project, basically just 2 short files and a Makefile, to show how to reproduce it.

I would not be surprised if it turns out that #8075 and #7198 are related to this issue.


I'm running my code on Arch Linux with this Crystal version:

Crystal 0.31.1 (2019-10-21)

LLVM: 9.0.0
Default target: x86_64-pc-linux-gnu
bug topicruntime

All 3 comments

Seems like we should be opening /proc/self/exe on linux at least.

This should be fixed in #8807

Yep seems fixed now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

relonger picture relonger  路  3Comments

nabeelomer picture nabeelomer  路  3Comments

costajob picture costajob  路  3Comments

RX14 picture RX14  路  3Comments

Sija picture Sija  路  3Comments