)]}'
{
  "commit": "86a53c0b2ead2d0da2a6bf91741c705df6b97f76",
  "tree": "3ac0a4122ab1d6719f56bc5be5dfb47a65fb39e4",
  "parents": [
    "aab2ac34d7f78f0b7a42cef0187dc6e4d7ec4f02"
  ],
  "author": {
    "name": "Simon Marchi",
    "email": "simon.marchi@polymtl.ca",
    "time": "Fri Mar 07 09:53:40 2025 -0500"
  },
  "committer": {
    "name": "Simon Marchi",
    "email": "simon.marchi@polymtl.ca",
    "time": "Fri Mar 07 21:53:11 2025 -0500"
  },
  "message": "gdb/dwarf: call other cutu_reader constructor in ensure_lang and dw2_get_file_names\n\nPR 32742 shows this failing:\n\n    $ make check TESTS\u003d\"gdb.ada/access_to_unbounded_array.exp\" RUNTESTFLAGS\u003d\"--target_board\u003dfission\"\n    Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.ada/access_to_unbounded_array.exp ...\n    FAIL: gdb.ada/access_to_unbounded_array.exp: scenario\u003dall: gdb_breakpoint: set breakpoint at foo.adb:23 (GDB internal error)\n\nOr, interactively:\n\n    $ ./gdb -q -nx --data-directory\u003ddata-directory testsuite/outputs/gdb.ada/access_to_unbounded_array/foo-all -ex \u0027b foo.adb:23\u0027 -batch\n    /home/simark/src/binutils-gdb/gdb/dwarf2/read.c:19567: internal-error: set_lang: Assertion `old_value \u003d\u003d language_unknown || old_value \u003d\u003d language_minimal || old_value \u003d\u003d lang\u0027 failed.\n\nThe symptom is that for a given dwarf2_per_cu, the language gets set\ntwice.  First, set to `language_ada`, and then, to `language_minimal`.\nIt\u0027s unexpected for the language of a CU to get changed like this.\n\nThe CU at offset 0x0 in the main file looks like:\n\n    0x00000000: Compile Unit: length \u003d 0x00000030, format \u003d DWARF32, version \u003d 0x0004, abbr_offset \u003d 0x0000, addr_size \u003d 0x08 (next unit at 0x00000034)\n\n    0x0000000b: DW_TAG_compile_unit\n                  DW_AT_low_pc [DW_FORM_addr]       (0x000000000000339a)\n                  DW_AT_high_pc [DW_FORM_data8]     (0x0000000000000432)\n                  DW_AT_stmt_list [DW_FORM_sec_offset]      (0x00000000)\n                  DW_AT_GNU_dwo_name [DW_FORM_strp] (\"b~foo.dwo\")\n                  DW_AT_comp_dir [DW_FORM_strp]     (\"/home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.ada/access_to_unbounded_array\")\n                  DW_AT_GNU_pubnames [DW_FORM_flag_present] (true)\n                  DW_AT_GNU_addr_base [DW_FORM_sec_offset]  (0x00000000)\n                  DW_AT_GNU_dwo_id [DW_FORM_data8]  (0x277aee54e7bd47f7)\n\nThis refers to the DWO file b~foo.dwo, whose top-level DIE is:\n\n    .debug_info.dwo contents:\n    0x00000000: Compile Unit: length \u003d 0x00000b63, format \u003d DWARF32, version \u003d 0x0004, abbr_offset \u003d 0x0000, addr_size \u003d 0x08 (next unit at 0x00000b67)\n\n    0x0000000b: DW_TAG_compile_unit\n                  DW_AT_producer [DW_FORM_GNU_str_index]    (\"GNU Ada 14.2.1 20250207 -fgnat-encodings\u003dminimal -gdwarf-4 -fdebug-types-section -fuse-ld\u003dgold -gnatA -gnatWb -gnatiw -gdwarf-4 -gsplit-dwarf -ggnu-pubnames -gnatws -mtune\u003dgeneric -march\u003dx86-64\")\n                  DW_AT_language [DW_FORM_data1]    (DW_LANG_Ada95)\n                  DW_AT_name [DW_FORM_GNU_str_index]        (\"/home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.ada/access_to_unbounded_array/b~foo.adb\")\n                  DW_AT_comp_dir [DW_FORM_GNU_str_index]    (\"/home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.ada/access_to_unbounded_array\")\n                  DW_AT_GNU_dwo_id [DW_FORM_data8]  (0xdbeffefab180a2cb)\n\nThe thing to note is that the language attribute is only present in the\nDIE in the DWO file, not on the DIE in the main file.\n\nThe first time the language gets set is here:\n\n    #0  dwarf2_per_cu::set_lang (this\u003d0x50f0000044b0, lang\u003dlanguage_ada, dw_lang\u003dDW_LANG_Ada95) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:20788\n    #1  0x0000555561666af6 in cutu_reader::prepare_one_comp_unit (this\u003d0x7ffff10bf2b0, cu\u003d0x51700008e000, pretend_language\u003dlanguage_minimal) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:21029\n    #2  0x000055556159f740 in cutu_reader::cutu_reader (this\u003d0x7ffff10bf2b0, this_cu\u003d0x50f0000044b0, per_objfile\u003d0x516000066080, abbrev_table\u003d0x510000004640, existing_cu\u003d0x0, skip_partial\u003dfalse, pretend_language\u003dlanguage_minimal, cache\u003d0x7ffff11b95e0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3371\n    #3  0x00005555615a547a in process_psymtab_comp_unit (this_cu\u003d0x50f0000044b0, per_objfile\u003d0x516000066080, storage\u003d0x7ffff11b95e0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3799\n    #4  0x00005555615a9292 in cooked_index_worker_debug_info::process_cus (this\u003d0x51700008dc80, task_number\u003d0, first\u003dstd::unique_ptr\u003cdwarf2_per_cu\u003e \u003d {...}, end\u003dstd::unique_ptr\u003cdwarf2_per_cu\u003e \u003d {...}) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:4122\n\nIn this code path (particularly this specific cutu_reader constructir),\nthe work is done to find and read the DWO file.  So the language is\nproperly identifier as language_ada, all good so far.\n\nThe second time the language gets set is:\n\n    #0  dwarf2_per_cu::set_lang (this\u003d0x50f0000044b0, lang\u003dlanguage_minimal, dw_lang\u003d0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:20788\n    #1  0x0000555561666af6 in cutu_reader::prepare_one_comp_unit (this\u003d0x7ffff0f42730, cu\u003d0x517000091b80, pretend_language\u003dlanguage_minimal) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:21029\n    #2  0x00005555615a1822 in cutu_reader::cutu_reader (this\u003d0x7ffff0f42730, this_cu\u003d0x50f0000044b0, per_objfile\u003d0x516000066080, pretend_language\u003dlanguage_minimal, parent_cu\u003d0x0, dwo_file\u003d0x0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3464\n    #3  0x000055556158c850 in dw2_get_file_names (this_cu\u003d0x50f0000044b0, per_objfile\u003d0x516000066080) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:1956\n    #4  0x000055556158f4f5 in dw_expand_symtabs_matching_file_matcher (per_objfile\u003d0x516000066080, file_matcher\u003d...) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:2157\n    #5  0x00005555616329e2 in cooked_index_functions::expand_symtabs_matching (this\u003d0x50200002ab50, objfile\u003d0x516000065780, file_matcher\u003d..., lookup_name\u003d0x0, symbol_matcher\u003d..., expansion_notify\u003d..., search_flags\u003d..., domain\u003d..., lang_matcher\u003d...) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:15912\n    #6  0x0000555562ca8a14 in objfile::map_symtabs_matching_filename (this\u003d0x516000065780, name\u003d0x50200002ad90 \"break pck.adb\", real_path\u003d0x0, callback\u003d...) at /home/smarchi/src/binutils-gdb/gdb/symfile-debug.c:207\n    #7  0x0000555562d68775 in iterate_over_symtabs (pspace\u003d0x513000005600, name\u003d0x50200002ad90 \"break pck.adb\", callback\u003d...) at /home/smarchi/src/binutils-gdb/gdb/symtab.c:727\n\nHere, we use the other cutu_reader constructor, the one that does not\nlook up the DWO file for the passed CU.  If a DWO file exists for this\nCU, the caller is expected to pass it as a parameter.  That cutu_reader\nconstructor also ends up setting the language of the CU.  But because it\ndidn\u0027t read the DWO file, it didn\u0027t figure out the language is\nlanguage_ada, so it tries to set the language to the default,\nlanguage_minimal.\n\nA question is: why do we end up trying to set the CU\u0027s language is this\ncontext.  This is completely unrelated to what we\u0027re trying to do, that\nis get the file names from the line table.  Setting the language is a\nside-effect of just constructing a cutu_reader, which we need to look up\nattributes in dw2_get_file_names_reader.  There are probably some\ncleanups to be done here, to avoid doing useless work like looking up\nand setting the CU\u0027s language when all we need is an object to help\nreading the DIEs and attributes.  But that is future work.\n\nThe same cutu_reader constructor is used in\n`dwarf2_per_cu::ensure_lang`.  Since this is the version of cutu_reader\nthat does not look up the DWO file, it will conclude that the language\nis language_minimal and set that as the CU\u0027s language.  In other words,\n`dwarf2_per_cu::ensure_lang` will get the language wrong, pretty ironic.\n\nFix this by using the other cutu_reader constructor in those two spots.\nPass `per_objfile-\u003eget_cu (this_cu)`, as the `existing_cu` parameter.  I\nthink this is necessary, because that constructor has an assert to check\nthat if `existing_cu` is nullptr, then there must not be an existing\n`dwarf2_cu` in the per_objfile.\n\nTo avoid getting things wrong like this, I think that the second\ncutu_reader constructor should be reserved for the spots that do pass a\nnon-nullptr dwo_file.  The only spot at the moment in\ncreate_cus_hash_table, where we read multiple units from the same DWO\nfile.  In this context, I guess it makes sense for efficiency to get the\ndwo_file once and pass it down to cutu_reader.  For that constructor,\nmake the parameters non-optional, add \"non-nullptr\" asserts, and update\nthe code to assume the passed values are not nullptr.\n\nWhat I don\u0027t know is if this change is problematic thread-wise, if the\nfunctions I have modified to use the other cutu_reader constructor can\nbe called concurrently in worker threads.  If so, I think it would be\nproblematic.\n\nBug: https://sourceware.org/bugzilla/show_bug.cgi?id\u003d32742\nChange-Id: I980d16875b9a43ab90e251504714d0d41165c7c8\nApproved-By: Tom Tromey \u003ctom@tromey.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "41532c8efecbf8b7c28c46612af862da4e25dc03",
      "old_mode": 33188,
      "old_path": "gdb/dwarf2/read.c",
      "new_id": "c5375b685676ddff17861e1bdf9146374fd9687b",
      "new_mode": 33188,
      "new_path": "gdb/dwarf2/read.c"
    },
    {
      "type": "modify",
      "old_id": "ef83bcfaf1747df1c471e273f65604d8131cb80c",
      "old_mode": 33188,
      "old_path": "gdb/dwarf2/read.h",
      "new_id": "b6ff433978c3bd18a23e94152ad77b6a8cfcf9a8",
      "new_mode": 33188,
      "new_path": "gdb/dwarf2/read.h"
    }
  ]
}
