radareorg / radare2

UNIX-like reverse engineering framework and command-line toolset
https://www.radare.org/
GNU Lesser General Public License v3.0
20.58k stars 3k forks source link

radare freezes program in Linux when attach #18663

Closed D1mon closed 1 year ago

D1mon commented 3 years ago

Same as #15937 but for Linux(Manjaro)

Environment

# copypaste this script into your shell and replace it with the output
Thu May  6 03:19:41 PM MSK 2021
radare2 5.2.1 0 @ linux-x86-64 git.5.2.1
commit: unknown build: 2021-04-26__23:00:17
Linux x86_64

Description

Any programs freezes after attach

Test

terminal 1: run kate

terminal 2: r2 -d <pid of kate>

kate freezes (buttons, keypress not working)

trufae commented 3 years ago

Yeah that's expected, you have to run dc to continue the execution of the process if you want that. If there's an issue after this it could be related to the way threads are processed

D1mon commented 3 years ago

Yes, it works, but sometimes needes few times dc. Application is running, but i can't put any radare command except ^C (Ctrl + C), and app freezes again.

radare commented 3 years ago

Then it seems that dc is not continuing all the threads. But only the currently selected one

On Fri, May 7, 2021, 9:05 AM D1mon @.***> wrote:

Yes, it works, but sometimes needes few times dc. Application is running, but i can't put any radare command except ^C (Ctrl + C), and app freezes again.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/radareorg/radare2/issues/18663#issuecomment-834121710, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG75FT357RLIRK4C5L67I3TMOGNJANCNFSM44G6F2TQ .

D1mon commented 3 years ago

I testing in gdb. In gdb same bug(maybe not bug, but i don't like this behavior). gdb freezes after attaching and unfreeze after cont and i can't input any commands until press ^C

trufae commented 3 years ago

Well thats how debuggers work. They have a blocking interface when the process is running. You cant interact with the debugee until the process is stoped again. Windows have some async apis but you cant do everything. In r2, the memory reads go thru the proc interface so if u just want to read write memory while the process runs you can do that. But reading registers and such is not possible or make sense at all

trufae commented 3 years ago

If you want interactivity use r2frida

trufae commented 3 years ago

Can you try setting -e dbg.threads=true ?

D1mon commented 3 years ago

No works, still freezes.

trufae commented 3 years ago

After dc? After attaching is expected and normal

D1mon commented 3 years ago

After dc - program works: unfreeze. But in radare i can't put any commands, need press ^C then program freeze but in radare i can put commands. One out of two. Either I can use a program or debugger. At the same time does not work. I need to constantly switch.

trufae commented 3 years ago

Yes, thats usually how debuggers work on Linux. because ptrace is blocking and must be used from the same thread.

D1mon commented 3 years ago

This may be correct, but it is not convenient. Is it possible to make it so that it does not block and it is possible to simultaneously work with both the program and the debugger?

D1mon commented 3 years ago

This may not apply to this topic, but I just wonder. And how then does Cheat Engine (CE) work? When CE works in the debugger mode, it does not block the program (game).

trufae commented 3 years ago

Cheat engine is a windows tool. Windows api permit that. On linux/mac the debugger needs to block/queue calls and have dedicated threads to handle this. Its just that r2 debugger for windows behaves like linux/mac debuggers work. Which nay not be the expected way.

This will eventually be addressed but its not yet done

gogo2464 commented 3 years ago

I really hope this issue does not come from cast on the refactor of this PR: https://github.com/radareorg/radare2/pull/18669

trufae commented 3 years ago

This is not an issue. Its normal behaviour and its not a regression. And no, your patch is harmless and unrelated