Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backtrace feature similar to strace #686

Open
Harvie opened this issue Jul 12, 2021 · 6 comments · May be fixed by #1270
Open

Backtrace feature similar to strace #686

Harvie opened this issue Jul 12, 2021 · 6 comments · May be fixed by #1270
Labels
new feature Completely new feature

Comments

@Harvie
Copy link

Harvie commented Jul 12, 2021

Hello,
currently i found it very useful to hit S key in the htop, to open strace window of selected thread. I absolutely love it and use it everyday. I've figured it currently executes following command:

strace -T -tt -s 512 -p 1497796

Would it also be possible to map B key to execute following command and show it's output?

cd /proc/1497796/cwd; gdb -batch -ex "bt" /proc/1497796/exe 1497796

I prints backtrace like this:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
0xf7f6a549 in __kernel_vsyscall ()
#0  0xf7f6a549 in __kernel_vsyscall ()
#1  0xf7a9a713 in __lll_lock_wait () from /usr/lib32/libpthread.so.0
#2  0xf7a92879 in pthread_mutex_lock () from /usr/lib32/libpthread.so.0
#3  0xf7e9999a in pthread_user_data_lock () at /home/dev/lib/pthread_extra/pthread_user_data.c:19
#4  0xf7e999eb in pthread_user_data_internal (thread=4050168512) at /home/dev/lib/pthread_extra/pthread_user_data.c:34
#5  0xf7e99379 in pthread_pause_enable () at /home/dev/lib/pthread_extra/pthread_pause.c:84
#6  0xf7e9953c in pthread_extra_thread_wrapper (arg=0x91eb8b0) at /home/dev/lib/pthread_extra/pthread_pause.c:253
#7  0xf7a90388 in start_thread () from /usr/lib32/libpthread.so.0
#8  0xf7d613da in clone () from /usr/lib32/libc.so.6
[Inferior 1 (process 1497796) detached]

Good thing about this is that i can see where the individual threads are getting stuck without having to use gdb manualy to attach to individual thread.

Please note that i use cd /proc/1497796/cwd; before calling gdb itself. The reason is that when using LD_PRELOAD with relative path, gdb can only find it when its run in same directory as the traced process.

Perhaps in addition to B key for backtrace, there can be even D key to launch full blown GDB attached to that process and switched to thread.

@BenBE BenBE added the new feature Completely new feature label Jul 12, 2021
@BenBE
Copy link
Member

BenBE commented Jul 12, 2021

There has been some discussion about "custom commands" for htop, which would allow you to do exactly this via some configuration. Cf. e.g. #638. IIRC there was some more discussion in other issues, but I can't find it right now. Basic idea was reserving just one key and then to present the suer with a menu of possible actions that could be configured via a configuration file.

NB: Also you may find bt full useful. ;-)

@Harvie
Copy link
Author

Harvie commented Jul 12, 2021

Basic idea was reserving just one key and then to present the suer with a menu of possible actions

Not sure about this, i really like that strace is quick and immediately available on S key, because i do it often. I also like the fact that i don't need to preconfigure that, because i work on many remote machines and configuring each of them would be hell. I beleive this is important feature to have on all machines, so even admin without much knowledge of debuggers can quickly see why process hangs.

NB: Also you may find bt full useful. ;-)

Thanks for the tip. It only adds another line which shows that there is nothing to show under each call. What am i supposed to see there? Update: tried on different binary and now i see call parameters in detail.

@BenBE
Copy link
Member

BenBE commented Jul 12, 2021

Basic idea was reserving just one key and then to present the suer with a menu of possible actions

Not sure about this, i really like that strace is quick and immediately available on S key, because i do it often. I also like the fact that i don't need to preconfigure that, because i work on many remote machines and configuring each of them would be hell.

Problem is we'd be running out of keys quite fast otherwise, as there's quite a few other features of that kind people asked for.

NB: Also you may find bt full useful. ;-)

Thanks for the tip. It only adds another line which shows that there is nothing to show under each call. What am i supposed to see there?

If debug symbols and stack frames are available this dumps the full set of arguments handed to each function.

@Harvie
Copy link
Author

Harvie commented Jul 12, 2021

Problem is we'd be running out of keys quite fast otherwise, as there's quite a few other features of that kind people asked for.

Perhaps it would make sense to dedicate SHIFT+KEY for these external utilities... So keys without shift can be still used by htop internaly. That would allow 26 tools to be implemented, which seems plenty. Just make sure CAPS LOCK is not affecting this. Or use CTRL/ALT if CAPS LOCK is a problem.

@BenBE
Copy link
Member

BenBE commented Jul 12, 2021

The idea was more like having one key which brings up a menu to select the desired tool. Could still use some key assignment in that menu based on shortcuts.

@Explorer09
Copy link
Contributor

Linking PR #1270 with this one. (Backtrace support draft for Linux. Requires libunwind and (optional) libiberty.)

@BenBE BenBE linked a pull request Feb 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Completely new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants