After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 791188 - Setting breakpoints for c code build under flatpak fails
Setting breakpoints for c code build under flatpak fails
Status: RESOLVED FIXED
Product: gnome-builder
Classification: Other
Component: plugins
3.27.x
Other Linux
: Normal normal
: ---
Assigned To: GNOME Builder Maintainers
GNOME Builder Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-12-04 03:39 UTC by Alberto Fanjul
Modified: 2017-12-05 02:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
translate Builder source file breakpoint into a path understandable by gdb (1.23 KB, patch)
2017-12-04 03:42 UTC, Alberto Fanjul
none Details | Review
gdb resolve source paths relative to builddir (1.93 KB, patch)
2017-12-04 23:44 UTC, Alberto Fanjul
none Details | Review
non-canonical path helper (7.63 KB, patch)
2017-12-05 00:56 UTC, Christian Hergert
none Details | Review
Use glib helper to uncanonicalize paths (1.74 KB, patch)
2017-12-05 02:20 UTC, Alberto Fanjul
none Details | Review

Description Alberto Fanjul 2017-12-04 03:39:59 UTC
Running a debug session for any c project compiled with flatpak the only breakpoint that works is the initial one (stop on main function). Using host it works correctly

Does this reproduce for you?

It doesn't make a difference, but as I will post code references I show here the source code used

https://github.com/albfan/gtask-example/

Seing log for debug session, main function is located in a main.c file which path is like:

Temporary breakpoint 1, main (argc=1, argv=0x7ffd97005c08) at ../../../../../../../../../Projects/gtask-example/src/main.c:61

Asking for relative and full path for source files to gdb:

-file-list-exec-source-files

you get a long list (shortened here to interesting file):

files=[
{file="../../../../../../../../../Projects/gtask-example/src/main.c"
,fullname="/home/alberto/.var/app/org.gnome.Builder/cache/gnome-builder/projects/gtask-example/builds/org.gnome.Gtask-Example.json-0601fcfb2fbf01231dd228e0b218301c589ae573-local-flatpak-org.gnome.Platform-x86_64-master/../../../../../../../../../Projects/gtask-example/src/main.c"}
...

It seems that gdb operates from a reference to builddir:

/home/alberto/.var/app/org.gnome.Builder/cache/gnome-builder/projects/gtask-example/builds/org.gnome.Gtask-Example.json-0601fcfb2fbf01231dd228e0b218301c589a    e573-local-flatpak-org.gnome.Platform-x86_64-master

I do ask gdb about its current working directory:

-environment-pwd

And says it is 

/home/alberto

Looking at path Builder pass to gdb

/home/alberto/Projects/gtask-example/src/main.c

it should be the same path (as applying ../ all the builddir dirs disappears)

But for whatever reason it doesn't.

This patch makes it work: translating replacing /home/alberto/ into buildir + (several ../)

I really don't know how to do this cleanly, so this is only a WIP.

To convert Builder file

/home/alberto/Projects/gtask-example/src/main.c

into gdb known file path:

/home/alberto/.var/app/org.gnome.Builder/cache/gnome-builder/projects/gtask-example/builds/org.gnome.Gtask-Example.json-0601fcfb2fbf01231dd228e0b218301c589ae573-local-flatpak-org.gnome.Platform-x86_64-master/../../../../../../../../../Projects/gtask-example/src/main.c

I guess we should:

1. Remove cwd from builddir

.var/app/org.gnome.Builder/cache/gnome-builder/projects/gtask-example/builds/org.gnome.Gtask-Example.json-0601fcfb2fbf01231dd228e0b218301c589ae573-local-flatpak-org.gnome.Platform-x86_64-master/

2 turn all that paths into ..

../../../../../../../../../

3. concat that with builddir

/home/alberto/.var/app/org.gnome.Builder/cache/gnome-builder/projects/gtask-example/builds/org.gnome.Gtask-Example.json-0601fcfb2fbf01231dd228e0b218301c589ae573-local-flatpak-org.gnome.Platform-x86_64-master/ + ../../../../../../../../../

4. Remove cwd from Builder path

Projects/gtask-example/src/main.c

5. concat

/home/alberto/.var/app/org.gnome.Builder/cache/gnome-builder/projects/gtask-example/builds/org.gnome.Gtask-Example.json-0601fcfb2fbf01231dd228e0b218301c589ae573-local-flatpak-org.gnome.Platform-x86_64-master/../../../../../../../../../ + Projects/gtask-example/src/main.c

I think I can implement that if the algorithm is correct, but maybe there's something better that will fix this
Comment 1 Alberto Fanjul 2017-12-04 03:42:35 UTC
Created attachment 364883 [details] [review]
translate Builder source file breakpoint into a path understandable by gdb

Just a WIP about the algorithm exposed
Comment 2 Alberto Fanjul 2017-12-04 23:44:14 UTC
Created attachment 364961 [details] [review]
gdb resolve source paths relative to builddir
Comment 3 Christian Hergert 2017-12-05 00:56:20 UTC
Created attachment 364963 [details] [review]
non-canonical path helper

This adds a helper we can use for non-canonical paths (along with tests to prove the implementation).
Comment 4 Alberto Fanjul 2017-12-05 02:20:23 UTC
Created attachment 364984 [details] [review]
Use glib helper to uncanonicalize paths
Comment 5 Christian Hergert 2017-12-05 02:46:39 UTC
Pushed with some cleanups.