You are not logged in.

#1 2022-02-11 20:23:36

kamocat
Member
Registered: 2014-08-21
Posts: 16

GDB can't insert breakpoint

I'm posting this here because it seems to be related to my system rather than confusion on how to use GDB.
I'm having trouble setting breakpoints in GDB. It will let me set them, but it fails to insert them.
I'm using gcc 11.1 and gdb 11.2 in Arch Linux on a chromebook (via Crostini).

Here's my test program:

int main(int argc, char ** argv){
    int a = 1;
    int b = 1;
    int c;
    // Simple fibonacci for testing
    for(int i = 0; i < 10; ++i){
        c = a + b;
        a = b;
        b = c;
    }
    return c;
}

which I compile with

gcc simple.c -g -ggdb -o simple.out

and debug with

gdb simple.out

Once in GDB, I attempt to set a breakpoint as follows:

(gdb) l
1       int main(int argc, char ** argv){
2           int a = 1;
3           int b = 1;
4           int c;
5           // Simple fibonacci for testing
6           for(int i = 0; i < 10; ++i){
7               c = a + b;
8               a = b;
9               b = c;
10          }
(gdb) b 7
Breakpoint 1 at 0x113b: file simple.c, line 7.
(gdb) run
Starting program: /home/kamocat/test/simple.out 
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x55555555513b

I tried updating and rebooting the VM, but this didn't change the result.
I think this is my first time using gdb on this system.

Offline

#2 2022-02-15 10:24:15

seth
Member
Registered: 2012-09-03
Posts: 29,026

Re: GDB can't insert breakpoint

You're using gdb properly.

cat /proc/sys/kernel/yama/ptrace_scope

https://www.kernel.org/doc/Documentatio … y/Yama.txt
Try to set it to "0" in case some pcap stuff fails in that lxc croissant ;-)

Offline

#3 2022-02-18 16:15:00

kamocat
Member
Registered: 2014-08-21
Posts: 16

Re: GDB can't insert breakpoint

My ptrace scope is currently set to 1. If I understand correctly, that should allow debugging if I start the program as a child process, e.g.

gdb simple.out

Nevertheless, I have attempted to relax my ptrace permissions.

/proc/sys/kernel/yama/ptrace_scope is not directly writeable. The permissions are read-only, with user and group of nobody.

Some suggest changing a parameter in /etc/sysctl.d/10-ptrace.conf, but this file does not exist on my system.

The kernel docs suggest changing the ptrace scope in C using

prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0);

. I tried this too, but GDB still failed to set the breakpoint.

New code:

#include <sys/prctl.h>
int main(int argc, char ** argv){
    prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0);
    int a = 1;
    int b = 1;
    int c;
    // Simple fibonacci for testing
    for(int i = 0; i < 10; ++i){
        c = a + b;
        a = b;
        b = c;
    }
    return c;
}

Offline

#4 2022-02-18 17:49:13

seth
Member
Registered: 2012-09-03
Posts: 29,026

Re: GDB can't insert breakpoint

/proc/sys/kernel/yama/ptrace_scope is not directly writeable. The permissions are read-only, with user and group of nobody.

???

stat /proc/sys/kernel/yama/ptrace_scope
cat /proc/sys/kernel/yama/ptrace_scope
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

Offline

#5 2022-02-18 17:51:46

kamocat
Member
Registered: 2014-08-21
Posts: 16

Re: GDB can't insert breakpoint

stat /proc/sys/kernel/yama/ptrace_scope
  File: /proc/sys/kernel/yama/ptrace_scope
  Size: 0               Blocks: 0          IO Block: 1024   regular empty file
Device: 0,60    Inode: 1358365     Links: 1
Access: (0644/-rw-r--r--)  Uid: (65534/  nobody)   Gid: (65534/  nobody)
Access: 2022-02-18 09:50:57.257605971 -0800
Modify: 2022-02-18 09:50:57.257605971 -0800
Change: 2022-02-18 09:50:57.257605971 -0800
 Birth: -

Offline

#6 2022-02-18 20:38:58

seth
Member
Registered: 2012-09-03
Posts: 29,026

Re: GDB can't insert breakpoint

Did you try to write into it as root?
You can also try passing "kernel.yama.ptrace_scope=0" to the kernel.
The weired ownership might be down to crostini…

Offline

#7 2022-02-18 21:19:15

kamocat
Member
Registered: 2014-08-21
Posts: 16

Re: GDB can't insert breakpoint

Yeah, I can't write to it as root.
I don't think there's a functioning way to pass kernel parameters in crostini. Sysctl didn't seem to have an effect. (I followed through with the suggestion from the unix stackexchange, created the file, and rebooted, but ptrace_scope still read as 1)

It looks like my next option is running a VM.

Offline

Board footer

Powered by FluxBB