)]}'
{
  "commit": "94de78f9d0d4b9eecb4e3efc393ffa4abbae662e",
  "tree": "f93f75fc0a78464b07d9f046e6fe45e96fac6910",
  "parents": [
    "903ea49d4780084fe8e6aac38e326cf29281eb08"
  ],
  "author": {
    "name": "Simon Marchi",
    "email": "simon.marchi@efficios.com",
    "time": "Wed Aug 06 15:31:36 2025 -0400"
  },
  "committer": {
    "name": "Simon Marchi",
    "email": "simon.marchi@efficios.com",
    "time": "Thu Aug 14 12:49:20 2025 -0400"
  },
  "message": "gdb/dwarf: clear per_bfd::num_{comp,type}_units on error\n\nCommit bedd6a7a44 (\"gdb/dwarf: track compilation and type unit count\")\ncauses this internal error:\n\n    $ ./gdb -nx -q --data-directory\u003ddata-directory testsuite/outputs/gdb.dwarf2/debug-names-duplicate-cu/debug-names-duplicate-cu -ex \"save gdb-index -dwarf-5 /tmp\" -batch\n\n    warning: Section .debug_names has incorrect number of CUs in CU table, ignoring .debug_names.\n    /home/smarchi/src/binutils-gdb/gdb/dwarf2/index-write.c:1454: internal-error: write_debug_names: Assertion `comp_unit_counter \u003d\u003d per_bfd-\u003enum_comp_units\u0027 failed.\n\nThis is visible when running this test:\n\n    $ make check TESTS\u003d\"gdb.dwarf2/debug-names-duplicate-cu.exp\" RUNTESTFLAGS\u003d\"--target_board\u003dcc-with-debug-names\"\n    ...\n    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.dwarf2/debug-names-duplicate-cu.exp ...\n    gdb compile failed, warning: Section .debug_names has incorrect number of CUs in CU table, ignoring .debug_names.\n    /home/smarchi/src/binutils-gdb/gdb/dwarf2/index-write.c:1454: internal-error: write_debug_names: Assertion `comp_unit_counter \u003d\u003d per_bfd-\u003enum_comp_units\u0027 failed.\n    ...\n                    \u003d\u003d\u003d gdb Summary \u003d\u003d\u003d\n\n    # of untested testcases         1\n\nHowever, it\u0027s easy to miss because it only causes an \"UNTESTED\" to be\nrecorded, not a FAIL or UNRESOLVED.  This is because the problem happens\nwhile trying to create the .debug_names index, as part of the test case\ncompilation.\n\nThe problem is: when we bail out from using .debug_names because we\ndetect it is inconsistent with the units in .debug_info, we clear\nper_bfd-\u003eall_units, to destroy all units previously created, before\nproceeding to read the units with an index.  However, we don\u0027t clear\nper_bfd-\u003enum_{comp,type}_units.  As a result, per_bfd-\u003eall_units\ncontains one unit, while per_bfd-\u003enum_comp_units is 2.  Whenever we\nclear per_bfd-\u003eall_units, we should also clear\nper_bfd-\u003enum_{comp,type}_units.\n\nWhile at it, move this logic inside a scoped object.\n\nI added an assertion in finalize_all_units to verify that the size of\nper_bfd-\u003eall_units equals per_bfd-\u003enum_comp_units +\nper_bfd-\u003enum_type_units.  This makes the problem (if omitting the fix)\nvisible when running gdb.dwarf2/debug-names-duplicate-cu.exp with the\nunix (default) target board:\n\n    ERROR: Couldn\u0027t load debug-names-duplicate-cu into GDB (GDB internal error).\n    FAIL: gdb.dwarf2/debug-names-duplicate-cu.exp: find index type (GDB internal error)\n    FAIL: gdb.dwarf2/debug-names-duplicate-cu.exp: find index type, check type is valid\n\n                    \u003d\u003d\u003d gdb Summary \u003d\u003d\u003d\n\n    # of expected passes            1\n    # of unexpected failures        2\n    # of unresolved testcases       1\n\nI considered changing the code to build a local vector of units first,\nthen move it in per_bfd-\u003eall_units on success, that would avoid having\nto clean it up on error.  I did not do it because it\u0027s a much larger\nchange, but we could consider it.\n\nChange-Id: I49bcc0cb4b34aba3d882b27c8a93c168e8875c08\nApproved-By: Tom Tromey \u003ctom@tromey.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "97677c04f6495480475f9272ff619356273c03cf",
      "old_mode": 33188,
      "old_path": "gdb/dwarf2/read-debug-names.c",
      "new_id": "ddf49356722653d754ee22c315409efd8d3f3c30",
      "new_mode": 33188,
      "new_path": "gdb/dwarf2/read-debug-names.c"
    },
    {
      "type": "modify",
      "old_id": "7dfba7324513818a210d93f1c8510ab3148ce76b",
      "old_mode": 33188,
      "old_path": "gdb/dwarf2/read-gdb-index.c",
      "new_id": "fc7b654be1a189721d55d98a68dd084fd852f4bb",
      "new_mode": 33188,
      "new_path": "gdb/dwarf2/read-gdb-index.c"
    },
    {
      "type": "modify",
      "old_id": "c37da5949b01e1e059bb2e0433dfe0d22a950503",
      "old_mode": 33188,
      "old_path": "gdb/dwarf2/read.c",
      "new_id": "7bd0850ee5b18fe95a014aab05ad2e62a87d8f54",
      "new_mode": 33188,
      "new_path": "gdb/dwarf2/read.c"
    },
    {
      "type": "modify",
      "old_id": "4e3f8d7d7bc432a875dc994247a4833235f8b602",
      "old_mode": 33188,
      "old_path": "gdb/dwarf2/read.h",
      "new_id": "74ec4204cadbc38d9d66f8a6a5cac432297a88ff",
      "new_mode": 33188,
      "new_path": "gdb/dwarf2/read.h"
    }
  ]
}
