[PATCH] gdb/jit: fix jit-reader linetable integrity

Simon Marchi simon.marchi@polymtl.ca
Sun Dec 22 02:12:36 GMT 2024



On 2024-12-21 03:30, Yang Liu wrote:
> The custom linetable functionality in GDB's JIT Interface has been broken
> since commit 1acc9dca423f78e44553928f0de839b618c13766.
> 
> In that commit, linetables were made independent from the objfile, which
> requires objfile->section_offsets to be initialized. However, section_offsets
> were never initialized in objfiles generated by GDB's JIT Interface
> with custom jit-readers, leading to GDB crashes when stepping into JITed code
> blocks with the following command already executed:
> 
>   jit-reader-load libmygdbjitreader.so
> 
> This patch fixes the issue by initializing the minimum section_offsets required
> for linetable parsing procedures.

I can imagine how the problem can manifest, but do you have a
reproducer?  I tried stepping with the binary of test
gdb.base/jit-reader.exp, but I couldn't get it to crash.  Ideally, this
fix should come with a test to demonstrate the problem and the fix.

> ---
>  gdb/jit.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/gdb/jit.c b/gdb/jit.c
> index 77d41bf86ba..7027c84b5bf 100644
> --- a/gdb/jit.c
> +++ b/gdb/jit.c
> @@ -665,6 +665,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb,
>  
>    objfile *objfile = objfile::make (nullptr, current_program_space,
>  				    objfile_name.c_str (), OBJF_NOT_FILENAME);
> +  objfile->section_offsets.assign (1, 0);

I would suggest using push_back instead of assign.  Everybody knows
push_back, whereas I had to look up what assign does, I guess I'm not
the only one.

Simon


More information about the Gdb-patches mailing list