gdb/jit: fix jit-reader linetable integrity

Message ID 20241222163153.11297-1-liuyang22@iscas.ac.cn
State New
Headers
Series gdb/jit: fix jit-reader linetable integrity |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed

Commit Message

Yang Liu Dec. 22, 2024, 4:31 p.m. UTC
  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.
---
 gdb/jit.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Yang Liu Dec. 22, 2024, 4:34 p.m. UTC | #1
Sorry, forgot to put a v2 in the title, please ignore this one.

On 2024/12/23 00:31, 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.
> ---
>   gdb/jit.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/gdb/jit.c b/gdb/jit.c
> index 77d41bf86ba..21c17c145c9 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.push_back (0);
> +  objfile->sect_index_text = 0;
>     objfile->per_bfd->gdbarch = priv_data->gdbarch;
>   
>     for (gdb_symtab &symtab : obj->symtabs)
  

Patch

diff --git a/gdb/jit.c b/gdb/jit.c
index 77d41bf86ba..21c17c145c9 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.push_back (0);
+  objfile->sect_index_text = 0;
   objfile->per_bfd->gdbarch = priv_data->gdbarch;
 
   for (gdb_symtab &symtab : obj->symtabs)