]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdbsupport] Workaround data race in get_print_cell
authorTom de Vries <tdevries@suse.de>
Fri, 15 Jul 2022 11:32:03 +0000 (13:32 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 21 Jul 2022 13:06:40 +0000 (15:06 +0200)
Data race between:
...
  Write of size 4 at 0x00000324eb60 by thread T2:
    #0 get_print_cell() gdbsupport/print-utils.cc:35 (gdb+0x1c032c7)
    #1 hex_string(long) gdbsupport/print-utils.cc:230 (gdb+0x1c03bc2)
    #2 sect_offset_str gdb/gdbtypes.h:82 (gdb+0x81b333)
    #3 process_queue_item gdb/dwarf2/read.c:7581 (gdb+0x831645)
...
and:
...
  Previous read of size 4 at 0x00000324eb60 by thread T3:
    #0 get_print_cell() gdbsupport/print-utils.cc:35 (gdb+0x1c032b4)
    #1 hex_string(long) gdbsupport/print-utils.cc:230 (gdb+0x1c03bc2)
    #2 sect_offset_str gdb/gdbtypes.h:82 (gdb+0x81b333)
    #3 process_queue_item gdb/dwarf2/read.c:7581 (gdb+0x831645)
...

For now, just do a malloc in get_print_cell to work around the data race.

gdbsupport/print-utils.cc

index 7bbb6deea749f077352481c67c7fa090890091e0..7d10743fa0d21fd2df0eb603756cc4a83eb92322 100644 (file)
 char *
 get_print_cell (void)
 {
-  static char buf[NUMCELLS][PRINT_CELL_SIZE];
-  static int cell = 0;
-
-  if (++cell >= NUMCELLS)
-    cell = 0;
-  return buf[cell];
+  return (char *)malloc (PRINT_CELL_SIZE);
 }
 
 static char *