[PATCH v2 02/14] gdb: clear inferior displaced stepping state and in-line step-over info on exec

Pedro Alves pedro@palves.net
Fri Dec 4 01:48:24 GMT 2020


On 12/2/20 3:47 PM, Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@efficios.com>
> 
> New in v2:
> 
> - A test!

Hurray!

> - I found (from the te st) that in-line step over exec hangs too,

"te st"

> Add a test with a program with two threads that does an exec.  The test
> includes the following axis:

plural -> axes


> To be able to precisely put a breakpoint on the syscall instruction, I
> added a small assembly file (lib/my-syscalls.S) that contains minimal
> Linux syscall wrappers.  I prefer that to the strategy used in
> gdb.base/step-over-syscall.exp, which is to stepi into the glibc wrapper
> until we find something that looks like a syscall instruction, I find
> that more predictable.

The downside of course is that this way you have to write the wrappers
for all archs and OSs.  I suppose an alternative would be to use
"catch syscall" and then "x /-i" to find the syscall instruction
address, like:

 (gdb) catch syscall execve
 Catchpoint 1 (syscall 'execve' [59])
 (gdb) r
 ...
 Thread 1 "execl" hit Catchpoint 1 (call to syscall execve), 0x00007ffff7e7a16b in execve () at ../sysdeps/unix/syscall-template.S:78
 (gdb) x /-i $pc
   0x7ffff7e7a169 <execve+9>:   syscall 
 (gdb) 

I don't object your approach though.

> gdb/ChangeLog:
> 
> 	* infrun.c (infrun_inferior_execd): New function.
> 	(_initialize_infrun): Attach inferior_execd observer.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.threads/step-over-exec-execd.c: New.

Missing copyright header on this file.

> 	* lib/my-syscalls.S: New.

I suppose the plan for other OSs, e.g., FreeBSD, is to use 
#ifdef in this file, like #ifdef __linux__ etc.?

> 	* lib/my-syscalls.h: New.

> --- /dev/null
> +++ b/gdb/testsuite/gdb.threads/step-over-exec-execd.c
> @@ -0,0 +1,13 @@
> +int a_variable_in_execd = 0;

I would suggest giving this variable a value != 0, since "0" is
also a typical "garbage" value.

> --- /dev/null
> +++ b/gdb/testsuite/lib/my-syscalls.S
> @@ -0,0 +1,46 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2020 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +
> +/* This file implements simple Linux syscall wrappers, to be used by tests that
> +   need to know exactly where the syscall instructions are.  */
> +
> +#include <asm/unistd.h>
> +
> +/* int my_execve (const char *file, char *argv[], char *envp[]);  */
> +
> +.global my_execve
> +my_execve:
> +
> +#if defined(__x86_64__)
> +
> +	mov $__NR_execve, %rax
> +	/* rdi, rsi and rdx already contain the right arguments.  */
> +my_execve_syscall:
> +	syscall
> +	ret
> +
> +#elif defined(__aarch64__)
> +
> +	mov x8, #__NR_execve
> +	/* x0, x1 and x2 already contain the right arguments.  */
> +my_execve_syscall:
> +	svc #0
> +
> +#else
> +# error "Unsupported architecture"
> +#endif

OK with the nits above fixed.

OOC, did you try porting this to 32-bit x86?


More information about the Gdb-patches mailing list