Commit Graph

316 Commits

Author SHA1 Message Date
7c378668e1 libsysprof: update radix tree sources 2023-01-26 11:03:39 -08:00
1e1a719895 Revert "libsysprof: Avoid a use-after-free in raxRemove"
This reverts commit bb83598b12.

See !63 and #84
2023-01-26 10:59:22 -08:00
bb83598b12 libsysprof: Avoid a use-after-free in raxRemove
As we are freeing the child, make sure to set it to NULL so that we are not
trying to remove it again.
2023-01-18 17:26:20 +01:00
ee71fb58b1 Fix LD_PRELOAD syntax
From ld.so(8): The items of the list can be separated
by spaces or colons...
2023-01-15 15:01:21 -05:00
6d50f3ca7b meson: Override dependencies to improve usage as a subproject
With this change, sysprof can be consumed as a subproject without
making any changes to the build files of a project. All you need to do
is provide a wrap file with a `[provide]` section:

https://mesonbuild.com/Wrap-dependency-system-manual.html#provide-section

This is also necessary because otherwise projects need to hard-code
the subproject name, which might be `sysprof` when using `wrap-git` or
`sysprof-3.46.0` when using `wrap-file` (to build from a release
tarball). This can cause conflicts between different subprojects that
consume sysprof differently.

Other projects like glib, cairo, pango, etc already do this.
2022-12-18 10:04:00 +05:30
6212396483 libsysprof: Actually set spawnable flags to inherit stdin
The code calculated flags but never actually set them on the spawnable,
so the `inherit-stdin` property did not work.

Fixes: 8799d2f0ca
See: https://gitlab.gnome.org/GNOME/sysprof/-/issues/76#note_1531919
2022-10-07 17:55:09 +00:00
1ef9fc1e30 elf: handle NULL lookaside
This code uses the hashtable directly to avoid the overhead of calling
the path which creates ProcessInfo entries. So we need to also handle
the chance the lookaside is NULL.
2022-09-05 20:51:58 -07:00
51e9123f6f libsysprof/preload: add example for tracing with -finstrument-functions
If we have tooling that can toggle -finstrument-functions, Builder for
example, then we'd be able to use an LD_PRELOAD to inject the various
function callbacks to record samples.

I dont think we want to use the sample frame type for this though. We
really want something focused on tracing instead and visualize it a bit
differently than the stack trace visualizer.
2022-07-25 23:37:34 -07:00
7ca2fef8ff libsysprof: cleanup backtrace helper types 2022-07-25 23:37:34 -07:00
c3035efd52 tools: add -Dagent=true option
This also builds the agent statically with libsysprof_static_dep since
we'd need that to avoid installing libsysprof when that isn't wanted.
It also ensures the LD_PRELOAD libraries are installed for use by the
agent.
2022-07-21 18:35:35 -07:00
e772197253 libsysprof: add signals for spawn/exit/term of subprocess
This is useful so that we can know when a subprocess has spawned by the
profiler in tooling which allows sysprof to spawn a process and monitor
said process. Additionally, we need to know when it exits so that we can
be correct in when we can call get_if_exited() from tooling.
2022-07-21 11:53:14 -07:00
d3076d1161 libsysprof: and always emit finished 2022-07-20 16:28:06 -07:00
5a88d5a0a1 libsysprof: handle NULL governor case gracefully 2022-07-20 16:25:09 -07:00
757d36ae8e Cleanup the build a bit
Makes the Meson build a little bit better and cleans up some of the
formatting.
2022-05-25 14:07:02 -05:00
8799d2f0ca libsysprof: add API to inherit stdin
Related #76
2022-04-01 12:57:02 -07:00
1587bc13b6 libsysprof: add accessors for setting spawnable flags
We need this to be able to allow inheriting stdin from sysprof-cli.
2022-04-01 12:41:49 -07:00
03652e1a44 proc: fix capture of mapped pathnames
pathnames are listed unescaped in /proc/[pid]/maps, so using %s as the
conversion specifier cuts pathnames off at space characters. Use %[^\n]
instead, to read everything until the end of the line.

Also, the scanf manpage states: "String input conversions store a
terminating null byte ('\0') to mark the end of the input; the maximum
field width does not include this terminator". So set the maximum field
width to 511 instead of 512, to leave one free byte in the buffer for
the terminating null byte.

Fixes #70
2021-11-23 14:41:31 +01:00
7a040a6032 memprof: add section for allocation leaks
These are defined by allocation records that do not have a corresponding
release record.
2021-11-04 21:10:44 -07:00
b3b2e61c19 enable_paranoid_cb: Do not use g_steal_pointer in callee argument list
The order in which the argument list is evaluated is unspecified, so it
was possible for g_steal_pointer to set self = NULL before
self->old_governor was evaluated, resulting in a crash:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f6efc678d84 in enable_paranoid_cb (object=0x561a4d147c80, result=0x561a4d173560, user_data=0x561a4d09d610) at ../src/libsysprof/sysprof-governor-source.c:290
290	                                        self->old_governor,
[Current thread is 1 (Thread 0x7f6efae4b600 (LWP 122786))]
(gdb) bt
#0  0x00007f6efc678d84 in enable_paranoid_cb (object=0x561a4d147c80 [SysprofHelpers], result=0x561a4d173560, user_data=0x561a4d09d610) at ../src/libsysprof/sysprof-governor-source.c:290
#1  0x00007f6efd51b389 in g_task_return_now (task=0x561a4d173560 [GTask]) at ../../../gio/gtask.c:1219
#2  0x00007f6efd51becb in g_task_return (type=<optimized out>, task=0x561a4d173560 [GTask]) at ../../../gio/gtask.c:1289
#3  g_task_return (task=0x561a4d173560 [GTask], type=<optimized out>) at ../../../gio/gtask.c:1245
#4  0x00007f6efc6a6060 in sysprof_helpers_set_paranoid_cb (object=0x561a4cf9df90 [IpcServiceProxy], result=0x561a4d1736e0, user_data=0x561a4d173560) at ../src/libsysprof/sysprof-helpers.c:788
#5  0x00007f6efd51b389 in g_task_return_now (task=0x561a4d1736e0 [GTask]) at ../../../gio/gtask.c:1219
#6  0x00007f6efd51becb in g_task_return (type=<optimized out>, task=0x561a4d1736e0 [GTask]) at ../../../gio/gtask.c:1289
#7  g_task_return (task=0x561a4d1736e0 [GTask], type=<optimized out>) at ../../../gio/gtask.c:1245
#8  0x00007f6efd5830cb in reply_cb (connection=<optimized out>, res=<optimized out>, user_data=user_data@entry=0x561a4d1736e0) at ../../../gio/gdbusproxy.c:2568
#9  0x00007f6efd51b389 in g_task_return_now (task=0x561a4d22b000 [GTask]) at ../../../gio/gtask.c:1219
#10 0x00007f6efd51becb in g_task_return (type=<optimized out>, task=0x561a4d22b000 [GTask]) at ../../../gio/gtask.c:1289
#11 g_task_return (task=0x561a4d22b000 [GTask], type=<optimized out>) at ../../../gio/gtask.c:1245
#12 0x00007f6efd577cbf in g_dbus_connection_call_done (source=<optimized out>, result=0x561a4d22b0c0, user_data=user_data@entry=0x561a4d22b000) at ../../../gio/gdbusconnection.c:5797
#13 0x00007f6efd51b389 in g_task_return_now (task=0x561a4d22b0c0 [GTask]) at ../../../gio/gtask.c:1219
#14 0x00007f6efd51b3c9 in complete_in_idle_cb (task=0x561a4d22b0c0) at ../../../gio/gtask.c:1233
#15 0x00007f6efd32db84 in g_main_dispatch (context=0x561a4cb60af0) at ../../../glib/gmain.c:3381
#16 g_main_context_dispatch (context=0x561a4cb60af0) at ../../../glib/gmain.c:4099
#17 0x00007f6efd32df28 in g_main_context_iterate (context=context@entry=0x561a4cb60af0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../../../glib/gmain.c:4175
#18 0x00007f6efd32dfdf in g_main_context_iteration (context=context@entry=0x561a4cb60af0, may_block=may_block@entry=1) at ../../../glib/gmain.c:4240
#19 0x00007f6efd54a06d in g_application_run (application=0x561a4cb56120 [SysprofApplication], argc=<optimized out>, argv=<optimized out>) at ../../../gio/gapplication.c:2569
#20 0x0000561a4b2edd14 in main (argc=1, argv=0x7ffddcebb708) at ../src/sysprof/sysprof.c:44
(gdb) info locals
helpers = 0x561a4d147c80 [SysprofHelpers]
self = 0x0
error = 0x0
old_governor = -1
__func__ = "enable_paranoid_cb"
2021-11-01 10:29:15 +01:00
32a7436837 binfile: Use correct prefix for debug files 2021-10-15 07:17:14 +03:00
46e7e31f45 elf-symbol-resolver: Add Flatpak Debug paths
Add paths for com.example.App.Debug and com.example.Sdk.Debug where most
of the debug symbols should lie.
2021-10-15 07:17:14 +03:00
01eafe951e elf-symbol-resolver: Use custom debug dirs
They were set up, but not actually used for resolving. Fix that.
2021-10-08 23:37:12 +03:00
3429249715 binfile: Fix debug message format strings 2021-10-08 23:37:12 +03:00
3b180b313b elfparser: Try original filename too
Fixes Sysprof running under Flatpak (e.g. from Builder) being unable to
resolve any paths on Silverblue.
2021-10-08 11:27:37 +03:00
b113c89af1 symbol-resolver: fix includes for close/lseek 2021-09-21 16:52:16 -07:00
3eca1ff409 symbol-resolver: remove unused function 2021-09-21 16:37:46 -07:00
d641856317 proc: ignore inode from podman processes
They never appear to be right anyway, so they just get in the way of
decoding anything (for which we might get right with a CRC check later).
2021-09-21 16:16:30 -07:00
a0de244f7e elf: add note about zero inodes 2021-09-21 16:03:58 -07:00
e62d6a07a2 podman: include image layers in overlay
We want the image layers so we can find the files in the base image
correctly.
2021-09-21 15:36:18 -07:00
5caebd29f4 podman: fix typo 2021-09-21 15:35:45 -07:00
bf8a851a57 elf: fix pid usage
We want the pid from the event.
2021-09-21 15:35:37 -07:00
11ae2fa395 build: fix write length 2021-09-21 13:12:02 -07:00
4c6912e804 elf: add helpers for test utilities to verify decoding 2021-09-21 11:50:03 -07:00
fb33d382cc extract instance data from .flatpak-info 2021-09-17 17:16:44 -07:00
728c5081d1 more work on resolver kinds 2021-09-17 17:11:06 -07:00
5f352abc86 do delayed path resolving of files containing symbols
we still need to teach this to locate debug dirs relative to the
process paths.
2021-09-15 17:52:58 -07:00
3e7e677419 start cleaning up proc source for delayed maps 2021-09-14 22:20:03 -07:00
e02785ba23 start on new resolver for paths 2021-09-14 19:53:46 -07:00
5f255403aa libsysprof: remove /sysroot/ workaround
This isnt really need anymore now that we have other ways of resolving this.
It fixes an issue with resolving some symbols on systems like GNOME OS.
2021-08-26 17:12:37 -07:00
bcda9694c6 profiler: fix typo in mutable calculation
Fixes #65
2021-06-03 13:57:38 -07:00
2c0ea406fd elf: use strncmp for comparison
We expect strncmp available on systems we build ELF parsers.
2021-03-17 13:01:02 -07:00
605cdfc3f1 elf: skip past /sysroot/ when symbol resolving
The /sysroot/ convention is something we see on OSTree-based systems
such as Silverblue or CoreOS which contains the running image. We can
skip that part of the path so that symbol resolving continues as normal.

We are starting to come into a situation where we need more advanced
path translations because we keep having to do things like this. Until
Linux figures out file-system namespaces at a higher level at least.
2021-03-17 12:56:38 -07:00
7e92b3e14b elf: use overlays to resolve library paths 2021-02-25 14:09:15 -08:00
43d2b0b019 proc: track overlays for flatpak /app and /usr 2021-02-25 13:44:58 -08:00
14139232d5 capture: rename PidRoot to Overlay and add src/dst
Really what we want to deal with here is tracking an overlay that we may
need to be able to decode after the fact (in case processes exit or we
need to do post-processing symbol resolution).

For the podman case, that is $some_path mapped to root (/), generally
speaking. For flatpak though, that would have two mappings, one for
/app and another for /usr (possibly more).
2021-02-25 13:43:09 -08:00
8b0f3f4682 proc: fix capture of application id 2021-02-25 13:03:46 -08:00
7a8f1d9d2e flatpak: add stubs to extra flatpak cgroup information
The goal here is to discover the app and runtime paths so that we can
create a path mapping when resolving addresses.
2021-02-25 12:15:15 -08:00
9e823c57ce elf: use discovered root when decoding symbols 2021-02-24 19:05:43 -08:00
bd8a8ada26 elf: track pid root when building lookaside buffers
We want to know the location of our root if it was specified in the
capture file. Such is useful for decoding symbols that may not be
reported right from perf tooling.

This allows us to try to translate maps for processes in containers.
2021-02-24 18:59:35 -08:00
b22899474d proc: discover filesystem root for podman containers
For processes we find in a podman container, we can sniff the libpod
cgroup scope. Using that we can translate into the podman layer that
contains the files.

With that, future work could find the proper .so when resolving based on
alternate roots for the process.
2021-02-24 18:40:41 -08:00