Bug 394520 - Attaching to running process generates empty file
Summary: Attaching to running process generates empty file
Status: RESOLVED FIXED
Alias: None
Product: Heaptrack
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Milian Wolff
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-21 14:24 UTC by Anthony Fieroni
Modified: 2021-08-13 10:03 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Fieroni 2018-05-21 14:24:25 UTC
Try to attach Heaptrack to running process result in empty file (0kb) even fifo file in /tmp is 0kb

1. Pull latest version
2. ./Heaptrack -p <pid> (in newest kernel ptrace has need privileges)
3."Injection finished" is last console output
4. Generated file is empty and stays at 0kb even hours of run
Comment 1 Milian Wolff 2018-05-22 07:30:49 UTC
I cannot reproduce this:

$ heaptrack -p $(pidof kwrite)

heaptrack output will be written to "/home/milian/projects/src/heaptrack/heaptrack.kwrite.15432.zst"
injecting heaptrack into application via GDB, this might take some time...
injection finished
# ctrl + o in kwrite
# then quit
heaptrack stats:
        allocations:            1417920
        leaked allocations:     3378
        temporary allocations:  295490
removing heaptrack injection via GDB, this might take some time...
ptrace: No such process.
No symbol table is loaded.  Use the "file" command.
The program is not being run.
Heaptrack finished! Now run the following to investigate the data:

  heaptrack --analyze "/home/milian/projects/src/heaptrack/heaptrack.kwrite.15432.zst"

please provide more information for me on how to reproduce this. what program are you tracing? what workload do you put on it?

also, please try to run tests/auto/tst_inject on your system - does it pass?
Comment 2 Anthony Fieroni 2018-05-22 09:01:50 UTC
[toni@toni-pc ~]$ uname -r
4.15.7-1

I start it like this
sudo ./heaptrack -p <plasmashell pid> (ptrace wants more privileges)
Plasmasheli is long-standing app, more than 11 days running, so created file is 0k, buti'm not quit plasmashell. Should i?
Comment 3 Milian Wolff 2018-05-22 10:05:42 UTC
No, you shouldn't need to quit plasma, just Ctrl + C to quick heaptrack eventually.

Also, try to elevate your ptrace rights and don't use sudo:

https://stackoverflow.com/questions/19215177/how-to-solve-ptrace-operation-not-permitted-when-trying-to-attach-gdb-to-a-pro
Comment 4 Anthony Fieroni 2018-05-22 15:35:40 UTC
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
Now it's work.
Comment 5 Milian Wolff 2018-05-23 09:52:52 UTC
I think we should better handle this scenario though, reopening to track progress on this.
Comment 6 karl-heinz reichel 2021-08-08 10:07:00 UTC
@Milian  
If this is more or less a configuration issue of the operating system
(means setting the ptrace_scope to 0 to enable Heaptrack tracing)
this issue could be closed.
IMHO hhere is no reasonable reason for Heaptrack to handle this case.
Comment 7 Milian Wolff 2021-08-13 09:45:03 UTC
we should at least give the user a clear indication of what's going on - i.e. forward this error message if needed (apparently that doesn't happen currently?)
Comment 8 Milian Wolff 2021-08-13 09:46:29 UTC
right - this is pretty confusing:

```
$ heaptrack -p $(pidof kontact)

heaptrack output will be written to "/home/milian/projects/kdab/qitissue/build-asan/heaptrack.kontact.102573.zst"
/home/milian/projects/compiled/other/lib/heaptrack/libheaptrack_preload.so
injecting heaptrack into application via GDB, this might take some time...
ptrace: Operation not permitted.
No symbol table is loaded.  Use the "file" command.
No symbol table is loaded.  Use the "file" command.
The program is not being run.
injection finished

^Cremoving heaptrack injection via GDB, this might take some time...
ptrace: Operation not permitted.
No symbol table is loaded.  Use the "file" command.
The program is not being run.
Heaptrack finished! Now run the following to investigate the data:

  heaptrack --analyze "/home/milian/projects/kdab/qitissue/build-asan/heaptrack.kontact.102573.zst"

```

we should stop directly after the first ptrace error
Comment 9 Milian Wolff 2021-08-13 10:03:40 UTC
Git commit 5cc1577c44b9e57840885f55a18b90dbfe3f8a59 by Milian Wolff.
Committed on 13/08/2021 at 09:59.
Pushed by mwolff into branch 'master'.

Don't try to runtime attach for /proc/sys/kernel/yama/ptrace_scope > 0

This won't work anyways, so let's error out early with a clear
error message.

M  +4    -0    src/track/heaptrack.sh.cmake

https://invent.kde.org/sdk/heaptrack/commit/5cc1577c44b9e57840885f55a18b90dbfe3f8a59