[Lldb-commits] [lldb] [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (PR #95015)
@@ -110,6 +108,9 @@ bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext _ctx) { strm.Printf("Note: Possible pointer authentication failure detected.\n"); }; + ABISP abi_sp = process.GetABI(); + assert(abi_sp && "Missing ABI info"); clayborg wrote: Do we really want to crash the debugger if there is no abi plug-in? I would like us to not crash by reporting an error to the debug console and being able to let the debugger live and just check `abi_sp` before we use it. https://github.com/llvm/llvm-project/pull/95015 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
@@ -133,6 +133,8 @@ struct ConstStringStats { struct StatisticsOptions { bool summary_only = false; bool load_all_debug_info = false; + bool include_targets = false; + bool include_modules = false; clayborg wrote: These should default to `true` if we are going to keep the old output if we just type `statistics dump`. https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_modules: Option<"modules", "m">, Group<2>, +Desc<"Dump statistics for the modules, including time and size of various " +"aspects of the module and debug information, type system, path, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_transcript: Option<"transcript", "t">, Group<2>, clayborg wrote: This one is fine since it didn't exist before to default to false. https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/clayborg requested changes to this pull request. https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; clayborg wrote: This should either take a boolean value which defaults to true: ``` --targets true or --targets=true --target false or --targets=false ``` And it should default to true. https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/clayborg edited https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_modules: Option<"modules", "m">, Group<2>, +Desc<"Dump statistics for the modules, including time and size of various " +"aspects of the module and debug information, type system, path, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; clayborg wrote: Ditto here. https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/clayborg commented: With these new options the default `statistics dump` changes the output from what is was before. I might suggest that we set the defaults so it does what it used to do by default, and then let users opt out of the targets and modules in each output. This means that the `--targets` and `--modules` would need to take a bool variable, or be switched to `--no-targets` and `--no-modules`. https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/royitaqi edited https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/95075 >From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Mon, 10 Jun 2024 17:04:11 -0700 Subject: [PATCH 1/5] Add --targets and --modules option to statistics dump --- lldb/include/lldb/Target/Statistics.h | 2 ++ lldb/source/Commands/CommandObjectStats.cpp | 6 ++ lldb/source/Commands/Options.td | 16 +--- lldb/source/Target/Statistics.cpp | 21 ++--- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index c04d529290fff..b24520b72a95d 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -133,6 +133,8 @@ struct ConstStringStats { struct StatisticsOptions { bool summary_only = false; bool load_all_debug_info = false; + bool include_targets = false; + bool include_modules = false; bool include_transcript = false; }; diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index 1935b0fdfadfb..1347b1ba25b1d 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed { case 'f': m_stats_options.load_all_debug_info = true; break; + case 'r': +m_stats_options.include_targets = true; +break; + case 'm': +m_stats_options.include_modules = true; +break; case 't': m_stats_options.include_transcript = true; break; diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index cee5a81d3796b..45f46334d5c73 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_modules: Option<"modules", "m">, Group<2>, +Desc<"Dump statistics for the modules, including time and size of various " +"aspects of the module and debug information, type system, path, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_transcript: Option<"transcript", "t">, Group<2>, Desc<"If the setting interpreter.save-transcript is enabled and this " "option is specified, include a JSON array with all commands the user and/" "or scripts executed during a debug session.">; diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index 2a5300012511a..13c430d73990e 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics( const bool summary_only = options.summary_only; const bool load_all_debug_info = options.load_all_debug_info; + const bool include_targets = options.include_targets; + const bool include_modules = options.include_modules; const bool include_transcript = options.include_transcript; json::Array json_targets; @@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics( {"totalSymbolTableStripped", num_stripped_modules}, }; - if (target) { -json_targets.emplace_back(target->ReportStatistics(options)); - } else { -for (const auto : debugger.GetTargetList().Targets()) + if (!summary_only || include_targets) { +if (target) { json_targets.emplace_back(target->ReportStatistics(options)); +} else { + for (const auto : debugger.GetTargetList().Targets()) +json_targets.emplace_back(target->ReportStatistics(options)); +} +
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/95075 >From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Mon, 10 Jun 2024 17:04:11 -0700 Subject: [PATCH 1/4] Add --targets and --modules option to statistics dump --- lldb/include/lldb/Target/Statistics.h | 2 ++ lldb/source/Commands/CommandObjectStats.cpp | 6 ++ lldb/source/Commands/Options.td | 16 +--- lldb/source/Target/Statistics.cpp | 21 ++--- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index c04d529290fff..b24520b72a95d 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -133,6 +133,8 @@ struct ConstStringStats { struct StatisticsOptions { bool summary_only = false; bool load_all_debug_info = false; + bool include_targets = false; + bool include_modules = false; bool include_transcript = false; }; diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index 1935b0fdfadfb..1347b1ba25b1d 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed { case 'f': m_stats_options.load_all_debug_info = true; break; + case 'r': +m_stats_options.include_targets = true; +break; + case 'm': +m_stats_options.include_modules = true; +break; case 't': m_stats_options.include_transcript = true; break; diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index cee5a81d3796b..45f46334d5c73 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_modules: Option<"modules", "m">, Group<2>, +Desc<"Dump statistics for the modules, including time and size of various " +"aspects of the module and debug information, type system, path, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_transcript: Option<"transcript", "t">, Group<2>, Desc<"If the setting interpreter.save-transcript is enabled and this " "option is specified, include a JSON array with all commands the user and/" "or scripts executed during a debug session.">; diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index 2a5300012511a..13c430d73990e 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics( const bool summary_only = options.summary_only; const bool load_all_debug_info = options.load_all_debug_info; + const bool include_targets = options.include_targets; + const bool include_modules = options.include_modules; const bool include_transcript = options.include_transcript; json::Array json_targets; @@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics( {"totalSymbolTableStripped", num_stripped_modules}, }; - if (target) { -json_targets.emplace_back(target->ReportStatistics(options)); - } else { -for (const auto : debugger.GetTargetList().Targets()) + if (!summary_only || include_targets) { +if (target) { json_targets.emplace_back(target->ReportStatistics(options)); +} else { + for (const auto : debugger.GetTargetList().Targets()) +json_targets.emplace_back(target->ReportStatistics(options)); +} +
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/95075 >From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Mon, 10 Jun 2024 17:04:11 -0700 Subject: [PATCH 1/3] Add --targets and --modules option to statistics dump --- lldb/include/lldb/Target/Statistics.h | 2 ++ lldb/source/Commands/CommandObjectStats.cpp | 6 ++ lldb/source/Commands/Options.td | 16 +--- lldb/source/Target/Statistics.cpp | 21 ++--- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index c04d529290fff..b24520b72a95d 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -133,6 +133,8 @@ struct ConstStringStats { struct StatisticsOptions { bool summary_only = false; bool load_all_debug_info = false; + bool include_targets = false; + bool include_modules = false; bool include_transcript = false; }; diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index 1935b0fdfadfb..1347b1ba25b1d 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed { case 'f': m_stats_options.load_all_debug_info = true; break; + case 'r': +m_stats_options.include_targets = true; +break; + case 'm': +m_stats_options.include_modules = true; +break; case 't': m_stats_options.include_transcript = true; break; diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index cee5a81d3796b..45f46334d5c73 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_modules: Option<"modules", "m">, Group<2>, +Desc<"Dump statistics for the modules, including time and size of various " +"aspects of the module and debug information, type system, path, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_transcript: Option<"transcript", "t">, Group<2>, Desc<"If the setting interpreter.save-transcript is enabled and this " "option is specified, include a JSON array with all commands the user and/" "or scripts executed during a debug session.">; diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index 2a5300012511a..13c430d73990e 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics( const bool summary_only = options.summary_only; const bool load_all_debug_info = options.load_all_debug_info; + const bool include_targets = options.include_targets; + const bool include_modules = options.include_modules; const bool include_transcript = options.include_transcript; json::Array json_targets; @@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics( {"totalSymbolTableStripped", num_stripped_modules}, }; - if (target) { -json_targets.emplace_back(target->ReportStatistics(options)); - } else { -for (const auto : debugger.GetTargetList().Targets()) + if (!summary_only || include_targets) { +if (target) { json_targets.emplace_back(target->ReportStatistics(options)); +} else { + for (const auto : debugger.GetTargetList().Targets()) +json_targets.emplace_back(target->ReportStatistics(options)); +} +
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r 1fe4f2d1a4b9d16ae41076608783df4427a4d985...f6c7737d056526714e65c35f0204b9b4a04776c3 lldb/test/API/commands/statistics/basic/TestStats.py `` View the diff from darker here. ``diff --- TestStats.py2024-06-11 04:33:57.00 + +++ TestStats.py2024-06-11 04:53:02.666221 + @@ -666,66 +666,66 @@ exe = self.getBuildArtifact("a.out") target = self.createTestTarget(file_path=exe) self.runCmd("settings set interpreter.save-transcript true") test_cases = [ -{ # statistics dump +{ # statistics dump "options": "", "expect": { "commands": True, "targets": True, "targets.moduleIdentifiers": True, "targets.breakpoints": True, "modules": True, "transcript": True, }, }, -{ # statistics dump --summary +{ # statistics dump --summary "options": " --summary", "expect": { "commands": False, "targets": False, "targets.moduleIdentifiers": False, "targets.breakpoints": False, "modules": False, "transcript": False, }, }, -{ # statistics dump --targets +{ # statistics dump --targets "options": " --targets", "expect": { "commands": True, "targets": True, "targets.moduleIdentifiers": False, "targets.breakpoints": True, "modules": False, "transcript": False, }, }, -{ # statistics dump --modules +{ # statistics dump --modules "options": " --modules", "expect": { "commands": True, "targets": False, "targets.moduleIdentifiers": False, "targets.breakpoints": False, "modules": True, "transcript": False, }, }, -{ # statistics dump --targets --modules +{ # statistics dump --targets --modules "options": " --targets --modules", "expect": { "commands": True, "targets": True, "targets.moduleIdentifiers": True, "targets.breakpoints": True, "modules": True, "transcript": False, }, }, -{ # statistics dump --transcript +{ # statistics dump --transcript "options": " --transcript", "expect": { "commands": True, "targets": False, "targets.moduleIdentifiers": False, @@ -738,25 +738,39 @@ for test_case in test_cases: options = test_case["options"] debug_stats = self.get_stats(options) # The following fields should always exist -self.assertIn("totalDebugInfoEnabled", debug_stats, "Global stats should always exist") +self.assertIn( +"totalDebugInfoEnabled", debug_stats, "Global stats should always exist" +) self.assertIn("memory", debug_stats, "'memory' should always exist") # The following fields should exist/not exist depending on the test case for field_name in test_case["expect"]: idx = field_name.find(".") if idx == -1: # `field` is a top-level field exists = field_name in debug_stats should_exist = test_case["expect"][field_name] should_exist_string = "" if should_exist else "not " -self.assertEqual(exists, should_exist, f"'{field_name}' should {should_exist_string}exist for 'statistics dump{options}'") +self.assertEqual( +exists, +should_exist, +f"'{field_name}' should {should_exist_string}exist for 'statistics dump{options}'", +) else: # `field` is a string of "." top_level_field_name = field_name[0:idx] -second_level_field_name = field_name[idx+1:] -for top_level_field in
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 1fe4f2d1a4b9d16ae41076608783df4427a4d985 f6c7737d056526714e65c35f0204b9b4a04776c3 -- lldb/include/lldb/Target/Statistics.h lldb/source/Commands/CommandObjectStats.cpp lldb/source/Target/Statistics.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index 15c7dfe07a..bbb556925e 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -111,7 +111,8 @@ TargetStats::ToJSON(Target , const bool include_targets = options.include_targets; const bool include_modules = options.include_modules; const bool include_transcript = options.include_transcript; - const bool include_default_sections = !summary_only && !include_targets && !include_modules && !include_transcript; + const bool include_default_sections = !summary_only && !include_targets && +!include_modules && !include_transcript; if (!summary_only) { CollectStats(target); @@ -234,7 +235,8 @@ llvm::json::Value DebuggerStats::ReportStatistics( const bool include_targets = options.include_targets; const bool include_modules = options.include_modules; const bool include_transcript = options.include_transcript; - const bool include_default_sections = !summary_only && !include_targets && !include_modules && !include_transcript; + const bool include_default_sections = !summary_only && !include_targets && +!include_modules && !include_transcript; json::Array json_targets; json::Array json_modules; `` https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
royitaqi wrote: cc @kusmour, @clayborg , @jeffreytan81 https://github.com/llvm/llvm-project/pull/95075 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: None (royitaqi) Changes # Add options The following options are added to the `statistics dump` command: * `--targets`: Dumps the `targets` section. * `--modules`: Dumps the `modules` section. When both options are given, the field `moduleIdentifiers` will be dumped for each target in the `targets` section. # Split options into groups We are splitting the section-selecting options into the following groups. * **Group 1**: `--summary`. This dumps only the summary. * **Group 2:** `--targets`, `--modules`, `--transcript`. This dumps both the summary and any of the specified sections. There is also an implicit **Group 0**, i.e. when none of the above options are given by the user. This dumps all sections. Other horizontal options (`--all-targets` and `--load-all-debug-info`) are accessible from all groups. # Tests ``` bin/llvm-lit -sv ../external/llvm-project/lldb/test/API/commands/statistics/basic/TestStats.py ``` A new test case `test_sections_existence` is added to verify that different sections are dumped/not dumped when different options are given. --- Full diff: https://github.com/llvm/llvm-project/pull/95075.diff 5 Files Affected: - (modified) lldb/include/lldb/Target/Statistics.h (+2) - (modified) lldb/source/Commands/CommandObjectStats.cpp (+6) - (modified) lldb/source/Commands/Options.td (+13-3) - (modified) lldb/source/Target/Statistics.cpp (+23-10) - (modified) lldb/test/API/commands/statistics/basic/TestStats.py (+96-6) ``diff diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index c04d529290fff..b24520b72a95d 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -133,6 +133,8 @@ struct ConstStringStats { struct StatisticsOptions { bool summary_only = false; bool load_all_debug_info = false; + bool include_targets = false; + bool include_modules = false; bool include_transcript = false; }; diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index 1935b0fdfadfb..1347b1ba25b1d 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed { case 'f': m_stats_options.load_all_debug_info = true; break; + case 'r': +m_stats_options.include_targets = true; +break; + case 'm': +m_stats_options.include_modules = true; +break; case 't': m_stats_options.include_transcript = true; break; diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index cee5a81d3796b..45f46334d5c73 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_modules: Option<"modules", "m">, Group<2>, +Desc<"Dump statistics for the modules, including time and size of various " +"aspects of the module and debug information, type system, path, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_transcript: Option<"transcript", "t">, Group<2>, Desc<"If the setting interpreter.save-transcript is enabled and this " "option is specified, include a JSON array with all commands the user and/" "or scripts executed during a debug session.">; diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index 2a5300012511a..15c7dfe07ac87 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -108,6 +108,10 @@
[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)
https://github.com/royitaqi created https://github.com/llvm/llvm-project/pull/95075 # Add options The following options are added to the `statistics dump` command: * `--targets`: Dumps the `targets` section. * `--modules`: Dumps the `modules` section. When both options are given, the field `moduleIdentifiers` will be dumped for each target in the `targets` section. # Split options into groups We are splitting the section-selecting options into the following groups. * **Group 1**: `--summary`. This dumps only the summary. * **Group 2:** `--targets`, `--modules`, `--transcript`. This dumps both the summary and any of the specified sections. There is also an implicit **Group 0**, i.e. when none of the above options are given by the user. This dumps all sections. Other horizontal options (`--all-targets` and `--load-all-debug-info`) are accessible from all groups. # Tests ``` bin/llvm-lit -sv ../external/llvm-project/lldb/test/API/commands/statistics/basic/TestStats.py ``` A new test case `test_sections_existence` is added to verify that different sections are dumped/not dumped when different options are given. >From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Mon, 10 Jun 2024 17:04:11 -0700 Subject: [PATCH 1/2] Add --targets and --modules option to statistics dump --- lldb/include/lldb/Target/Statistics.h | 2 ++ lldb/source/Commands/CommandObjectStats.cpp | 6 ++ lldb/source/Commands/Options.td | 16 +--- lldb/source/Target/Statistics.cpp | 21 ++--- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lldb/include/lldb/Target/Statistics.h b/lldb/include/lldb/Target/Statistics.h index c04d529290fff..b24520b72a95d 100644 --- a/lldb/include/lldb/Target/Statistics.h +++ b/lldb/include/lldb/Target/Statistics.h @@ -133,6 +133,8 @@ struct ConstStringStats { struct StatisticsOptions { bool summary_only = false; bool load_all_debug_info = false; + bool include_targets = false; + bool include_modules = false; bool include_transcript = false; }; diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index 1935b0fdfadfb..1347b1ba25b1d 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed { case 'f': m_stats_options.load_all_debug_info = true; break; + case 'r': +m_stats_options.include_targets = true; +break; + case 'm': +m_stats_options.include_modules = true; +break; case 't': m_stats_options.include_transcript = true; break; diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index cee5a81d3796b..45f46334d5c73 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1416,16 +1416,26 @@ let Command = "trace schema" in { } let Command = "statistics dump" in { - def statistics_dump_all: Option<"all-targets", "a">, Group<1>, + def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>, Desc<"Include statistics for all targets.">; def statistics_dump_summary: Option<"summary", "s">, Group<1>, Desc<"Dump only high-level summary statistics. " "Exclude targets, modules, breakpoints etc... details.">; - def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>, + def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 2>, Desc<"Dump the total possible debug info statistics. " "Force loading all the debug information if not yet loaded, and collect " "statistics with those.">; - def statistics_dump_transcript: Option<"transcript", "t">, Group<1>, + def statistics_dump_targets: Option<"targets", "r">, Group<2>, +Desc<"Dump statistics for the targets, including breakpoints, expression " +"evaluations, frame variables, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_modules: Option<"modules", "m">, Group<2>, +Desc<"Dump statistics for the modules, including time and size of various " +"aspects of the module and debug information, type system, path, etc. " +"If both the '--targets' and the '--modules' options are specified, a " +"list of module identifiers will be added to the 'targets' section.">; + def statistics_dump_transcript: Option<"transcript", "t">, Group<2>, Desc<"If the setting interpreter.save-transcript is enabled and this " "option is specified, include a JSON array with all commands the user and/" "or scripts executed during a debug session.">; diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index 2a5300012511a..13c430d73990e 100644 ---
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
https://github.com/jasonmolenda closed https://github.com/llvm/llvm-project/pull/95067 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 1934208 - [lldb] NFC add comments and test case for ObjectFileMachO delay-init (#95067)
Author: Jason Molenda Date: 2024-06-10T20:33:38-07:00 New Revision: 1934208132e3a084c5952656ae29816958b8207c URL: https://github.com/llvm/llvm-project/commit/1934208132e3a084c5952656ae29816958b8207c DIFF: https://github.com/llvm/llvm-project/commit/1934208132e3a084c5952656ae29816958b8207c.diff LOG: [lldb] NFC add comments and test case for ObjectFileMachO delay-init (#95067) Add comments and a test for delay-init libraries on macOS. I originally added the support in 954d00e87cdd77d0e9e367be52e62340467bd779 a month ago, but without these additional clarifications. rdar://126885033 Added: lldb/test/API/macosx/delay-init-dependency/Makefile lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py lldb/test/API/macosx/delay-init-dependency/foo.c lldb/test/API/macosx/delay-init-dependency/main.c Modified: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Removed: diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 4dd23bb1e4dbe..2979bf69bf762 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5140,12 +5140,20 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList ) { case LC_LOADFVMLIB: case LC_LOAD_UPWARD_DYLIB: { uint32_t name_offset = cmd_offset + m_data.GetU32(); +// For LC_LOAD_DYLIB there is an alternate encoding +// which adds a uint32_t `flags` field for `DYLD_USE_*` +// flags. This can be detected by a timestamp field with +// the `DYLIB_USE_MARKER` constant value. bool is_delayed_init = false; uint32_t use_command_marker = m_data.GetU32(); if (use_command_marker == 0x1a741800 /* DYLIB_USE_MARKER */) { offset += 4; /* uint32_t current_version */ offset += 4; /* uint32_t compat_version */ uint32_t flags = m_data.GetU32(); + // If this LC_LOAD_DYLIB is marked delay-init, + // don't report it as a dependent library -- it + // may be loaded in the process at some point, + // but will most likely not be load at launch. if (flags & 0x08 /* DYLIB_USE_DELAYED_INIT */) is_delayed_init = true; } diff --git a/lldb/test/API/macosx/delay-init-dependency/Makefile b/lldb/test/API/macosx/delay-init-dependency/Makefile new file mode 100644 index 0..246ea0f34e1a1 --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/Makefile @@ -0,0 +1,11 @@ +C_SOURCES := main.c +LD_EXTRAS := -L. -Wl,-delay_library,libfoo.dylib + +.PHONY: build-libfoo +all: build-libfoo a.out + +include Makefile.rules + +build-libfoo: foo.c + $(MAKE) -f $(MAKEFILE_RULES) \ + DYLIB_C_SOURCES=foo.c DYLIB_NAME=foo DYLIB_ONLY=YES diff --git a/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py new file mode 100644 index 0..44ed2b1d21f18 --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py @@ -0,0 +1,62 @@ +"""Test binaries with delay-init dependencies.""" + +import subprocess +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDelayInitDependencies(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +@skipUnlessDarwin +def test_delay_init_dependency(self): +TestBase.setUp(self) +out = subprocess.run( +["xcrun", "ld", "-delay_library"], +universal_newlines=True, +stdout=subprocess.PIPE, +stderr=subprocess.PIPE, +) +if "delay_library missing" not in out.stderr: +self.skipTest( +"Skipped because the linker doesn't know about -delay_library" +) +self.build() +main_source = "main.c" +exe = self.getBuildArtifact("a.out") +lib = self.getBuildArtifact("libfoo.dylib") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# libfoo.dylib should not be in the target pre-execution +for m in target.modules: +self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib") + +# This run without arguments will not load libfoo.dylib +li = lldb.SBLaunchInfo([]) +li.SetWorkingDirectory(self.getBuildDir()) +(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( +self, "// break here", lldb.SBFileSpec("main.c"), li +) +for m in target.modules: +self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib") + +process.Kill() +self.dbg.DeleteTarget(target) + +# This
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/95067 >From 6b67c214ea95418e3f246c694d0a40009176fc07 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Mon, 10 Jun 2024 17:52:42 -0700 Subject: [PATCH 1/2] [lldb] NFC add comments and test case for ObjectFileMachO delay-init Add comments and a test for delay-init libraries on macOS. I originally added the support in 954d00e87cdd77d0e9e367be52e62340467bd779 a month ago, but without these additional clarifications. rdar://126885033 --- .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 8 +++ .../API/macosx/delay-init-dependency/Makefile | 11 .../TestDelayInitDependency.py| 63 +++ .../API/macosx/delay-init-dependency/foo.c| 1 + .../API/macosx/delay-init-dependency/main.c | 9 +++ 5 files changed, 92 insertions(+) create mode 100644 lldb/test/API/macosx/delay-init-dependency/Makefile create mode 100644 lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py create mode 100644 lldb/test/API/macosx/delay-init-dependency/foo.c create mode 100644 lldb/test/API/macosx/delay-init-dependency/main.c diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 4dd23bb1e4dbe..2979bf69bf762 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5140,12 +5140,20 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList ) { case LC_LOADFVMLIB: case LC_LOAD_UPWARD_DYLIB: { uint32_t name_offset = cmd_offset + m_data.GetU32(); +// For LC_LOAD_DYLIB there is an alternate encoding +// which adds a uint32_t `flags` field for `DYLD_USE_*` +// flags. This can be detected by a timestamp field with +// the `DYLIB_USE_MARKER` constant value. bool is_delayed_init = false; uint32_t use_command_marker = m_data.GetU32(); if (use_command_marker == 0x1a741800 /* DYLIB_USE_MARKER */) { offset += 4; /* uint32_t current_version */ offset += 4; /* uint32_t compat_version */ uint32_t flags = m_data.GetU32(); + // If this LC_LOAD_DYLIB is marked delay-init, + // don't report it as a dependent library -- it + // may be loaded in the process at some point, + // but will most likely not be load at launch. if (flags & 0x08 /* DYLIB_USE_DELAYED_INIT */) is_delayed_init = true; } diff --git a/lldb/test/API/macosx/delay-init-dependency/Makefile b/lldb/test/API/macosx/delay-init-dependency/Makefile new file mode 100644 index 0..246ea0f34e1a1 --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/Makefile @@ -0,0 +1,11 @@ +C_SOURCES := main.c +LD_EXTRAS := -L. -Wl,-delay_library,libfoo.dylib + +.PHONY: build-libfoo +all: build-libfoo a.out + +include Makefile.rules + +build-libfoo: foo.c + $(MAKE) -f $(MAKEFILE_RULES) \ + DYLIB_C_SOURCES=foo.c DYLIB_NAME=foo DYLIB_ONLY=YES diff --git a/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py new file mode 100644 index 0..9b9b1618ba6de --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py @@ -0,0 +1,63 @@ +"""Test binaries with delay-init dependencies.""" + +import subprocess +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDelayInitDependencies(TestBase): + +NO_DEBUG_INFO_TESTCASE = True + +@skipUnlessDarwin +def test_delay_init_dependency(self): +TestBase.setUp(self) +out = subprocess.run( +["xcrun", "ld", "-delay_library"], +universal_newlines=True, +stdout=subprocess.PIPE, +stderr=subprocess.PIPE, +) +if "delay_library missing" not in out.stderr: +self.skipTest( +"Skipped because the linker doesn't know about -delay_library" +) +self.build() +main_source = "main.c" +exe = self.getBuildArtifact("a.out") +lib = self.getBuildArtifact("libfoo.dylib") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# libfoo.dylib should not be in the target pre-execution +for m in target.modules: +self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib") + +# This run without arguments will not load libfoo.dylib +li = lldb.SBLaunchInfo([]) +li.SetWorkingDirectory(self.getBuildDir()) +(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( +self, "// break here", lldb.SBFileSpec("main.c"), li +) +for m in target.modules: +
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
https://github.com/jasonmolenda updated https://github.com/llvm/llvm-project/pull/95067 >From 6b67c214ea95418e3f246c694d0a40009176fc07 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Mon, 10 Jun 2024 17:52:42 -0700 Subject: [PATCH 1/2] [lldb] NFC add comments and test case for ObjectFileMachO delay-init Add comments and a test for delay-init libraries on macOS. I originally added the support in 954d00e87cdd77d0e9e367be52e62340467bd779 a month ago, but without these additional clarifications. rdar://126885033 --- .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 8 +++ .../API/macosx/delay-init-dependency/Makefile | 11 .../TestDelayInitDependency.py| 63 +++ .../API/macosx/delay-init-dependency/foo.c| 1 + .../API/macosx/delay-init-dependency/main.c | 9 +++ 5 files changed, 92 insertions(+) create mode 100644 lldb/test/API/macosx/delay-init-dependency/Makefile create mode 100644 lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py create mode 100644 lldb/test/API/macosx/delay-init-dependency/foo.c create mode 100644 lldb/test/API/macosx/delay-init-dependency/main.c diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 4dd23bb1e4dbe..2979bf69bf762 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5140,12 +5140,20 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList ) { case LC_LOADFVMLIB: case LC_LOAD_UPWARD_DYLIB: { uint32_t name_offset = cmd_offset + m_data.GetU32(); +// For LC_LOAD_DYLIB there is an alternate encoding +// which adds a uint32_t `flags` field for `DYLD_USE_*` +// flags. This can be detected by a timestamp field with +// the `DYLIB_USE_MARKER` constant value. bool is_delayed_init = false; uint32_t use_command_marker = m_data.GetU32(); if (use_command_marker == 0x1a741800 /* DYLIB_USE_MARKER */) { offset += 4; /* uint32_t current_version */ offset += 4; /* uint32_t compat_version */ uint32_t flags = m_data.GetU32(); + // If this LC_LOAD_DYLIB is marked delay-init, + // don't report it as a dependent library -- it + // may be loaded in the process at some point, + // but will most likely not be load at launch. if (flags & 0x08 /* DYLIB_USE_DELAYED_INIT */) is_delayed_init = true; } diff --git a/lldb/test/API/macosx/delay-init-dependency/Makefile b/lldb/test/API/macosx/delay-init-dependency/Makefile new file mode 100644 index 0..246ea0f34e1a1 --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/Makefile @@ -0,0 +1,11 @@ +C_SOURCES := main.c +LD_EXTRAS := -L. -Wl,-delay_library,libfoo.dylib + +.PHONY: build-libfoo +all: build-libfoo a.out + +include Makefile.rules + +build-libfoo: foo.c + $(MAKE) -f $(MAKEFILE_RULES) \ + DYLIB_C_SOURCES=foo.c DYLIB_NAME=foo DYLIB_ONLY=YES diff --git a/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py new file mode 100644 index 0..9b9b1618ba6de --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py @@ -0,0 +1,63 @@ +"""Test binaries with delay-init dependencies.""" + +import subprocess +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDelayInitDependencies(TestBase): + +NO_DEBUG_INFO_TESTCASE = True + +@skipUnlessDarwin +def test_delay_init_dependency(self): +TestBase.setUp(self) +out = subprocess.run( +["xcrun", "ld", "-delay_library"], +universal_newlines=True, +stdout=subprocess.PIPE, +stderr=subprocess.PIPE, +) +if "delay_library missing" not in out.stderr: +self.skipTest( +"Skipped because the linker doesn't know about -delay_library" +) +self.build() +main_source = "main.c" +exe = self.getBuildArtifact("a.out") +lib = self.getBuildArtifact("libfoo.dylib") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# libfoo.dylib should not be in the target pre-execution +for m in target.modules: +self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib") + +# This run without arguments will not load libfoo.dylib +li = lldb.SBLaunchInfo([]) +li.SetWorkingDirectory(self.getBuildDir()) +(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( +self, "// break here", lldb.SBFileSpec("main.c"), li +) +for m in target.modules: +
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
jasonmolenda wrote: the formatter is whining about an extra newline in a test file https://github.com/llvm/llvm-project/pull/95067 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
https://github.com/JDevlieghere approved this pull request. LGTM if the formatter's happy. https://github.com/llvm/llvm-project/pull/95067 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r c4f8ae6f32dadf9383c94ed13152d91f68631255...6b67c214ea95418e3f246c694d0a40009176fc07 lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py `` View the diff from darker here. ``diff --- TestDelayInitDependency.py 2024-06-11 00:54:46.00 + +++ TestDelayInitDependency.py 2024-06-11 01:11:31.243472 + @@ -6,11 +6,10 @@ from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil class TestDelayInitDependencies(TestBase): - NO_DEBUG_INFO_TESTCASE = True @skipUnlessDarwin def test_delay_init_dependency(self): TestBase.setUp(self) `` https://github.com/llvm/llvm-project/pull/95067 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jason Molenda (jasonmolenda) Changes Add comments and a test for delay-init libraries on macOS. I originally added the support in 954d00e87cdd77d0e9e367be52e62340467bd779 a month ago, but without these additional clarifications. rdar://126885033 --- Full diff: https://github.com/llvm/llvm-project/pull/95067.diff 5 Files Affected: - (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (+8) - (added) lldb/test/API/macosx/delay-init-dependency/Makefile (+11) - (added) lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py (+63) - (added) lldb/test/API/macosx/delay-init-dependency/foo.c (+1) - (added) lldb/test/API/macosx/delay-init-dependency/main.c (+9) ``diff diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 4dd23bb1e4dbe..2979bf69bf762 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5140,12 +5140,20 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList ) { case LC_LOADFVMLIB: case LC_LOAD_UPWARD_DYLIB: { uint32_t name_offset = cmd_offset + m_data.GetU32(); +// For LC_LOAD_DYLIB there is an alternate encoding +// which adds a uint32_t `flags` field for `DYLD_USE_*` +// flags. This can be detected by a timestamp field with +// the `DYLIB_USE_MARKER` constant value. bool is_delayed_init = false; uint32_t use_command_marker = m_data.GetU32(); if (use_command_marker == 0x1a741800 /* DYLIB_USE_MARKER */) { offset += 4; /* uint32_t current_version */ offset += 4; /* uint32_t compat_version */ uint32_t flags = m_data.GetU32(); + // If this LC_LOAD_DYLIB is marked delay-init, + // don't report it as a dependent library -- it + // may be loaded in the process at some point, + // but will most likely not be load at launch. if (flags & 0x08 /* DYLIB_USE_DELAYED_INIT */) is_delayed_init = true; } diff --git a/lldb/test/API/macosx/delay-init-dependency/Makefile b/lldb/test/API/macosx/delay-init-dependency/Makefile new file mode 100644 index 0..246ea0f34e1a1 --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/Makefile @@ -0,0 +1,11 @@ +C_SOURCES := main.c +LD_EXTRAS := -L. -Wl,-delay_library,libfoo.dylib + +.PHONY: build-libfoo +all: build-libfoo a.out + +include Makefile.rules + +build-libfoo: foo.c + $(MAKE) -f $(MAKEFILE_RULES) \ + DYLIB_C_SOURCES=foo.c DYLIB_NAME=foo DYLIB_ONLY=YES diff --git a/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py new file mode 100644 index 0..9b9b1618ba6de --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py @@ -0,0 +1,63 @@ +"""Test binaries with delay-init dependencies.""" + +import subprocess +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDelayInitDependencies(TestBase): + +NO_DEBUG_INFO_TESTCASE = True + +@skipUnlessDarwin +def test_delay_init_dependency(self): +TestBase.setUp(self) +out = subprocess.run( +["xcrun", "ld", "-delay_library"], +universal_newlines=True, +stdout=subprocess.PIPE, +stderr=subprocess.PIPE, +) +if "delay_library missing" not in out.stderr: +self.skipTest( +"Skipped because the linker doesn't know about -delay_library" +) +self.build() +main_source = "main.c" +exe = self.getBuildArtifact("a.out") +lib = self.getBuildArtifact("libfoo.dylib") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# libfoo.dylib should not be in the target pre-execution +for m in target.modules: +self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib") + +# This run without arguments will not load libfoo.dylib +li = lldb.SBLaunchInfo([]) +li.SetWorkingDirectory(self.getBuildDir()) +(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( +self, "// break here", lldb.SBFileSpec("main.c"), li +) +for m in target.modules: +self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib") + +process.Kill() +self.dbg.DeleteTarget(target) + +# This run with one argument will load libfoo.dylib +li = lldb.SBLaunchInfo([]) +li.SetWorkingDirectory(self.getBuildDir()) +li.SetArguments(["one-argument"], True) +(target, process, thread, bkpt) =
[Lldb-commits] [lldb] [lldb] NFC add comments and test case for ObjectFileMachO delay-init (PR #95067)
https://github.com/jasonmolenda created https://github.com/llvm/llvm-project/pull/95067 Add comments and a test for delay-init libraries on macOS. I originally added the support in 954d00e87cdd77d0e9e367be52e62340467bd779 a month ago, but without these additional clarifications. rdar://126885033 >From 6b67c214ea95418e3f246c694d0a40009176fc07 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Mon, 10 Jun 2024 17:52:42 -0700 Subject: [PATCH] [lldb] NFC add comments and test case for ObjectFileMachO delay-init Add comments and a test for delay-init libraries on macOS. I originally added the support in 954d00e87cdd77d0e9e367be52e62340467bd779 a month ago, but without these additional clarifications. rdar://126885033 --- .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 8 +++ .../API/macosx/delay-init-dependency/Makefile | 11 .../TestDelayInitDependency.py| 63 +++ .../API/macosx/delay-init-dependency/foo.c| 1 + .../API/macosx/delay-init-dependency/main.c | 9 +++ 5 files changed, 92 insertions(+) create mode 100644 lldb/test/API/macosx/delay-init-dependency/Makefile create mode 100644 lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py create mode 100644 lldb/test/API/macosx/delay-init-dependency/foo.c create mode 100644 lldb/test/API/macosx/delay-init-dependency/main.c diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 4dd23bb1e4dbe..2979bf69bf762 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5140,12 +5140,20 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList ) { case LC_LOADFVMLIB: case LC_LOAD_UPWARD_DYLIB: { uint32_t name_offset = cmd_offset + m_data.GetU32(); +// For LC_LOAD_DYLIB there is an alternate encoding +// which adds a uint32_t `flags` field for `DYLD_USE_*` +// flags. This can be detected by a timestamp field with +// the `DYLIB_USE_MARKER` constant value. bool is_delayed_init = false; uint32_t use_command_marker = m_data.GetU32(); if (use_command_marker == 0x1a741800 /* DYLIB_USE_MARKER */) { offset += 4; /* uint32_t current_version */ offset += 4; /* uint32_t compat_version */ uint32_t flags = m_data.GetU32(); + // If this LC_LOAD_DYLIB is marked delay-init, + // don't report it as a dependent library -- it + // may be loaded in the process at some point, + // but will most likely not be load at launch. if (flags & 0x08 /* DYLIB_USE_DELAYED_INIT */) is_delayed_init = true; } diff --git a/lldb/test/API/macosx/delay-init-dependency/Makefile b/lldb/test/API/macosx/delay-init-dependency/Makefile new file mode 100644 index 0..246ea0f34e1a1 --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/Makefile @@ -0,0 +1,11 @@ +C_SOURCES := main.c +LD_EXTRAS := -L. -Wl,-delay_library,libfoo.dylib + +.PHONY: build-libfoo +all: build-libfoo a.out + +include Makefile.rules + +build-libfoo: foo.c + $(MAKE) -f $(MAKEFILE_RULES) \ + DYLIB_C_SOURCES=foo.c DYLIB_NAME=foo DYLIB_ONLY=YES diff --git a/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py new file mode 100644 index 0..9b9b1618ba6de --- /dev/null +++ b/lldb/test/API/macosx/delay-init-dependency/TestDelayInitDependency.py @@ -0,0 +1,63 @@ +"""Test binaries with delay-init dependencies.""" + +import subprocess +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestDelayInitDependencies(TestBase): + +NO_DEBUG_INFO_TESTCASE = True + +@skipUnlessDarwin +def test_delay_init_dependency(self): +TestBase.setUp(self) +out = subprocess.run( +["xcrun", "ld", "-delay_library"], +universal_newlines=True, +stdout=subprocess.PIPE, +stderr=subprocess.PIPE, +) +if "delay_library missing" not in out.stderr: +self.skipTest( +"Skipped because the linker doesn't know about -delay_library" +) +self.build() +main_source = "main.c" +exe = self.getBuildArtifact("a.out") +lib = self.getBuildArtifact("libfoo.dylib") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# libfoo.dylib should not be in the target pre-execution +for m in target.modules: +self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib") + +# This run without arguments will not load libfoo.dylib +li = lldb.SBLaunchInfo([]) +
[Lldb-commits] [lldb] Fix type lookup bug where wrong decl context was being used for a DIE. (PR #94846)
https://github.com/clayborg updated https://github.com/llvm/llvm-project/pull/94846 >From 2f579ecafeaeb735cbce1bcfc829eb52a93f067c Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Fri, 7 Jun 2024 23:56:03 -0700 Subject: [PATCH 1/3] Fix type lookup bug where wrong decl context was being used for a DIE. The function that calculated the declaration context for a DIE was incorrectly transparently traversing acrosss DW_TAG_subprogram dies when climbing the parent DIE chain. This meant that types defined in functions would appear to have the declaration context of anything above the function. I fixed the GetTypeLookupContextImpl(...) function in DWARFDIE.cpp to not transparently skip over functions, lexical blocks and inlined functions and compile and type units. Added a test to verify things are working. --- .../Plugins/SymbolFile/DWARF/DWARFDIE.cpp | 12 .../API/functionalities/type_types/Makefile | 2 + .../type_types/TestFindTypes.py | 69 +++ .../API/functionalities/type_types/main.cpp | 16 + 4 files changed, 99 insertions(+) create mode 100644 lldb/test/API/functionalities/type_types/Makefile create mode 100644 lldb/test/API/functionalities/type_types/TestFindTypes.py create mode 100644 lldb/test/API/functionalities/type_types/main.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp index 7cf92adc6ef57..c10174e8848ee 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -491,6 +491,18 @@ static void GetTypeLookupContextImpl(DWARFDIE die, case DW_TAG_base_type: push_ctx(CompilerContextKind::Builtin, name); break; +// If any of the tags below appear in the parent chain, stop the decl +// context and return. Prior to these being in here, if a type existed in a +// namespace "a" like "a::my_struct", but we also have a function in that +// same namespace "a" which contained a type named "my_struct", both would +// return "a::my_struct" as the declaration context since the +// DW_TAG_subprogram would be skipped and its parent would be found. +case DW_TAG_compile_unit: +case DW_TAG_type_unit: +case DW_TAG_subprogram: +case DW_TAG_lexical_block: +case DW_TAG_inlined_subroutine: + return; default: break; } diff --git a/lldb/test/API/functionalities/type_types/Makefile b/lldb/test/API/functionalities/type_types/Makefile new file mode 100644 index 0..3d0b98f13f3d7 --- /dev/null +++ b/lldb/test/API/functionalities/type_types/Makefile @@ -0,0 +1,2 @@ +CXX_SOURCES := main.cpp +include Makefile.rules diff --git a/lldb/test/API/functionalities/type_types/TestFindTypes.py b/lldb/test/API/functionalities/type_types/TestFindTypes.py new file mode 100644 index 0..adbaaba51d080 --- /dev/null +++ b/lldb/test/API/functionalities/type_types/TestFindTypes.py @@ -0,0 +1,69 @@ +""" +Test the SBModule and SBTarget type lookup APIs to find multiple types. +""" + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TypeFindFirstTestCase(TestBase): +def test_find_first_type(self): +""" +Test SBTarget::FindTypes() and SBModule::FindTypes() APIs. + +We had issues where our declaration context when finding types was +incorrectly calculated where a type in a namepace, and a type in a +function that was also in the same namespace would match a lookup. For +example: + +namespace a { + struct Foo { +int foo; + }; + + unsigned foo() { +typedef unsigned Foo; +Foo foo = 12; +return foo; + } +} // namespace a + + +Previously LLDB would calculate the declaration context of "a::Foo" +correctly, but incorrectly calculate the declaration context of "Foo" +from within the foo() function as "a::Foo". Adding tests to ensure this +works correctly. +""" +self.build() +target = self.createTestTarget() +exe_module = target.GetModuleAtIndex(0) +self.assertTrue(exe_module.IsValid()) +# Test the SBTarget and SBModule APIs for FindFirstType +for api in [target, exe_module]: +# We should find the "a::Foo" but not the "Foo" type in the function +types = api.FindTypes("a::Foo") +self.assertEqual(types.GetSize(), 1) +type_str0 = str(types.GetTypeAtIndex(0)) +self.assertIn('struct Foo', type_str0) + +# When we search by type basename, we should find any type whose +# basename matches "Foo", so "a::Foo" and the "Foo" type in the +# function. +types = api.FindTypes("Foo") +self.assertEqual(types.GetSize(), 2) +
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
https://github.com/clayborg updated https://github.com/llvm/llvm-project/pull/87740 >From c364215cef4d383bf5cb51bf61d442a5bc9fbfe9 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Sat, 30 Mar 2024 10:50:34 -0700 Subject: [PATCH 1/8] Add support for using foreign type units in .debug_names. This patch adds support for the new foreign type unit support in .debug_names. Features include: - don't manually index foreign TUs if we have info for them - only use the type unit entries that match the .dwo files when we have a .dwp file - fix crashers that happen due to PeekDIEName() using wrong offsets --- .../SymbolFile/DWARF/DWARFDebugInfo.cpp | 18 .../Plugins/SymbolFile/DWARF/DWARFDebugInfo.h | 2 + .../SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 65 - .../SymbolFile/DWARF/DebugNamesDWARFIndex.h | 6 +- .../SymbolFile/DWARF/ManualDWARFIndex.cpp | 6 +- .../SymbolFile/DWARF/ManualDWARFIndex.h | 7 +- .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 66 -- .../SymbolFile/DWARF/SymbolFileDWARF.h| 9 ++ .../DWARF/x86/dwp-foreign-type-units.cpp | 91 +++ .../DebugInfo/DWARF/DWARFAcceleratorTable.h | 11 +++ .../DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 13 +++ 11 files changed, 257 insertions(+), 37 deletions(-) create mode 100644 lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp index c37cc91e08ed1..056c6d4b0605f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -222,6 +222,20 @@ DWARFUnit *DWARFDebugInfo::GetUnitAtOffset(DIERef::Section section, return result; } +DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef _ref) { + // Make sure we get the correct SymbolFileDWARF from the DIERef before + // asking for information from a debug info object. We might start with the + // DWARFDebugInfo for the main executable in a split DWARF and the DIERef + // might be pointing to a specific .dwo file or to the .dwp file. So this + // makes sure we get the right SymbolFileDWARF instance before finding the + // DWARFUnit that contains the offset. If we just use this object to do the + // search, we might be using the wrong .debug_info section from the wrong + // file with an offset meant for a different section. + SymbolFileDWARF *dwarf = m_dwarf.GetDIERefSymbolFile(die_ref); + return dwarf->DebugInfo().GetUnitContainingDIEOffset(die_ref.section(), + die_ref.die_offset()); +} + DWARFUnit * DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section, dw_offset_t die_offset) { @@ -232,6 +246,10 @@ DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section, return result; } +const std::shared_ptr DWARFDebugInfo::GetDwpSymbolFile() { + return m_dwarf.GetDwpSymbolFile(); +} + DWARFTypeUnit *DWARFDebugInfo::GetTypeUnitForHash(uint64_t hash) { auto pos = llvm::lower_bound(m_type_hash_to_unit_index, std::make_pair(hash, 0u), llvm::less_first()); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h index 4706b55d38ea9..4d4555a338252 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -52,6 +52,8 @@ class DWARFDebugInfo { const DWARFDebugAranges (); + const std::shared_ptr GetDwpSymbolFile(); + protected: typedef std::vector UnitColl; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 56717bab1ecd8..a07c454ea7ee3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -34,6 +34,18 @@ DebugNamesDWARFIndex::Create(Module , DWARFDataExtractor debug_names, module, std::move(index_up), debug_names, debug_str, dwarf)); } + +llvm::DenseSet +DebugNamesDWARFIndex::GetTypeUnitSigs(const DebugNames _names) { + llvm::DenseSet result; + for (const DebugNames::NameIndex : debug_names) { +const uint32_t num_tus = ni.getForeignTUCount(); +for (uint32_t tu = 0; tu < num_tus; ++tu) + result.insert(ni.getForeignTUSignature(tu)); + } + return result; +} + llvm::DenseSet DebugNamesDWARFIndex::GetUnits(const DebugNames _names) { llvm::DenseSet result; @@ -48,17 +60,22 @@ DebugNamesDWARFIndex::GetUnits(const DebugNames _names) { return result; } +DWARFTypeUnit * +DebugNamesDWARFIndex::GetForeignTypeUnit(const DebugNames::Entry ) const { + std::optional type_sig = entry.getForeignTUTypeSignature(); + if (type_sig) +if (auto dwp_sp = m_debug_info.GetDwpSymbolFile()) + return
[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)
@@ -657,6 +657,42 @@ std::optional DWARFDebugNames::Entry::getLocalTUOffset() const { return NameIdx->getLocalTUOffset(*Index); } +std::optional +DWARFDebugNames::Entry::getForeignTUTypeSignature() const { + std::optional Index = getLocalTUIndex(); + const uint32_t NumLocalTUs = NameIdx->getLocalTUCount(); + if (!Index || *Index < NumLocalTUs) +return std::nullopt; // Invalid TU index or TU index is for a local TU + // The foreign TU index is the TU index minus the number of local TUs. + const uint64_t ForeignTUIndex = *Index - NumLocalTUs; + if (ForeignTUIndex >= NameIdx->getForeignTUCount()) +return std::nullopt; // Invalid foreign TU index. + return NameIdx->getForeignTUSignature(ForeignTUIndex); +} + +std::optional +DWARFDebugNames::Entry::getForeignTUSkeletonCUOffset() const { + // Must have a DW_IDX_type_unit and it must be a foreign type unit. + if (!getForeignTUTypeSignature()) clayborg wrote: It is still necessary otherwise we will think it is just the one and only `DW_IDX_comp_unit`, not the one any only `DW_IDX_type_unit`... https://github.com/llvm/llvm-project/pull/87740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix type lookup bug where wrong decl context was being used for a DIE. (PR #94846)
https://github.com/clayborg updated https://github.com/llvm/llvm-project/pull/94846 >From 2f579ecafeaeb735cbce1bcfc829eb52a93f067c Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Fri, 7 Jun 2024 23:56:03 -0700 Subject: [PATCH 1/2] Fix type lookup bug where wrong decl context was being used for a DIE. The function that calculated the declaration context for a DIE was incorrectly transparently traversing acrosss DW_TAG_subprogram dies when climbing the parent DIE chain. This meant that types defined in functions would appear to have the declaration context of anything above the function. I fixed the GetTypeLookupContextImpl(...) function in DWARFDIE.cpp to not transparently skip over functions, lexical blocks and inlined functions and compile and type units. Added a test to verify things are working. --- .../Plugins/SymbolFile/DWARF/DWARFDIE.cpp | 12 .../API/functionalities/type_types/Makefile | 2 + .../type_types/TestFindTypes.py | 69 +++ .../API/functionalities/type_types/main.cpp | 16 + 4 files changed, 99 insertions(+) create mode 100644 lldb/test/API/functionalities/type_types/Makefile create mode 100644 lldb/test/API/functionalities/type_types/TestFindTypes.py create mode 100644 lldb/test/API/functionalities/type_types/main.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp index 7cf92adc6ef57..c10174e8848ee 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -491,6 +491,18 @@ static void GetTypeLookupContextImpl(DWARFDIE die, case DW_TAG_base_type: push_ctx(CompilerContextKind::Builtin, name); break; +// If any of the tags below appear in the parent chain, stop the decl +// context and return. Prior to these being in here, if a type existed in a +// namespace "a" like "a::my_struct", but we also have a function in that +// same namespace "a" which contained a type named "my_struct", both would +// return "a::my_struct" as the declaration context since the +// DW_TAG_subprogram would be skipped and its parent would be found. +case DW_TAG_compile_unit: +case DW_TAG_type_unit: +case DW_TAG_subprogram: +case DW_TAG_lexical_block: +case DW_TAG_inlined_subroutine: + return; default: break; } diff --git a/lldb/test/API/functionalities/type_types/Makefile b/lldb/test/API/functionalities/type_types/Makefile new file mode 100644 index 0..3d0b98f13f3d7 --- /dev/null +++ b/lldb/test/API/functionalities/type_types/Makefile @@ -0,0 +1,2 @@ +CXX_SOURCES := main.cpp +include Makefile.rules diff --git a/lldb/test/API/functionalities/type_types/TestFindTypes.py b/lldb/test/API/functionalities/type_types/TestFindTypes.py new file mode 100644 index 0..adbaaba51d080 --- /dev/null +++ b/lldb/test/API/functionalities/type_types/TestFindTypes.py @@ -0,0 +1,69 @@ +""" +Test the SBModule and SBTarget type lookup APIs to find multiple types. +""" + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TypeFindFirstTestCase(TestBase): +def test_find_first_type(self): +""" +Test SBTarget::FindTypes() and SBModule::FindTypes() APIs. + +We had issues where our declaration context when finding types was +incorrectly calculated where a type in a namepace, and a type in a +function that was also in the same namespace would match a lookup. For +example: + +namespace a { + struct Foo { +int foo; + }; + + unsigned foo() { +typedef unsigned Foo; +Foo foo = 12; +return foo; + } +} // namespace a + + +Previously LLDB would calculate the declaration context of "a::Foo" +correctly, but incorrectly calculate the declaration context of "Foo" +from within the foo() function as "a::Foo". Adding tests to ensure this +works correctly. +""" +self.build() +target = self.createTestTarget() +exe_module = target.GetModuleAtIndex(0) +self.assertTrue(exe_module.IsValid()) +# Test the SBTarget and SBModule APIs for FindFirstType +for api in [target, exe_module]: +# We should find the "a::Foo" but not the "Foo" type in the function +types = api.FindTypes("a::Foo") +self.assertEqual(types.GetSize(), 1) +type_str0 = str(types.GetTypeAtIndex(0)) +self.assertIn('struct Foo', type_str0) + +# When we search by type basename, we should find any type whose +# basename matches "Foo", so "a::Foo" and the "Foo" type in the +# function. +types = api.FindTypes("Foo") +self.assertEqual(types.GetSize(), 2) +
[Lldb-commits] [lldb] [lldb] Add a test for lea_rsp_pattern_p to x86 unwinder (NFC) (PR #94852)
https://github.com/jasonmolenda approved this pull request. Ah wait, it's because x86_64 functions on entry have the CFA == $rsp+8, right. So you add 16 to rsp and now the CFA is $rsp-8. This is good to merge. Do you have access to do that yourself? https://github.com/llvm/llvm-project/pull/94852 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add a test for lea_rsp_pattern_p to x86 unwinder (NFC) (PR #94852)
jasonmolenda wrote: Hi, thanks for the PR. I wrote the x86 unwinder but I don't work with the ISA very often any more, I'm a little confused. Shouldn't the sp offset after this instruction executes be 16? The test is testing for 8. I'm sure I've misunderstood the effects of the instruction. https://github.com/llvm/llvm-project/pull/94852 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix type lookup bug where wrong decl context was being used for a DIE. (PR #94846)
@@ -0,0 +1,69 @@ +""" +Test the SBModule and SBTarget type lookup APIs to find multiple types. +""" + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TypeFindFirstTestCase(TestBase): +def test_find_first_type(self): +""" +Test SBTarget::FindTypes() and SBModule::FindTypes() APIs. + +We had issues where our declaration context when finding types was +incorrectly calculated where a type in a namepace, and a type in a +function that was also in the same namespace would match a lookup. For +example: + +namespace a { + struct Foo { +int foo; + }; + + unsigned foo() { +typedef unsigned Foo; +Foo foo = 12; +return foo; + } +} // namespace a + + +Previously LLDB would calculate the declaration context of "a::Foo" +correctly, but incorrectly calculate the declaration context of "Foo" +from within the foo() function as "a::Foo". Adding tests to ensure this +works correctly. +""" +self.build() +target = self.createTestTarget() +exe_module = target.GetModuleAtIndex(0) +self.assertTrue(exe_module.IsValid()) +# Test the SBTarget and SBModule APIs for FindFirstType +for api in [target, exe_module]: +# We should find the "a::Foo" but not the "Foo" type in the function +types = api.FindTypes("a::Foo") +self.assertEqual(types.GetSize(), 1) +type_str0 = str(types.GetTypeAtIndex(0)) +self.assertIn('struct Foo', type_str0) + +# When we search by type basename, we should find any type whose +# basename matches "Foo", so "a::Foo" and the "Foo" type in the +# function. +types = api.FindTypes("Foo") +self.assertEqual(types.GetSize(), 2) +type_str0 = str(types.GetTypeAtIndex(0)) +type_str1 = str(types.GetTypeAtIndex(1)) +# We don't know which order the types will come back as, so +if 'struct Foo' in type_str0: +self.assertIn('typedef Foo', type_str1) +else: +self.assertIn('struct Foo', type_str1) + +# When we search by type basename with "::" prepended, we should +# only types in the root namespace which means only "Foo" type in clayborg wrote: So I don't know of anyone that would use the function name when asking for a type, even if that type was defined in a function. To make the expression parser work, we should be able to find all of the types using a context like just "Foo", where we would find both `::Foo` and the `Foo` from `a::foo()`, but sort the results based on the CompilerDeclContext of each type that was returned. If we are evaluating an expression in `a::foo()`, the `Foo` type from that function could tell us the CompilerDeclContext it was defined in and we would find the closest match to where the expression is being run. https://github.com/llvm/llvm-project/pull/94846 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (PR #95015)
jasonmolenda wrote: this is fine but fwiw there are `Process::FixAnyAddress`, `Process::FixDataAddress`, `Process::FixCodeAddress` methods that are the preferred way of clearing pointerauth bits and they fall back to returning the value unmodified if there is no ABI. https://github.com/llvm/llvm-project/pull/95015 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix type lookup bug where wrong decl context was being used for a DIE. (PR #94846)
@@ -0,0 +1,69 @@ +""" +Test the SBModule and SBTarget type lookup APIs to find multiple types. +""" + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TypeFindFirstTestCase(TestBase): +def test_find_first_type(self): +""" +Test SBTarget::FindTypes() and SBModule::FindTypes() APIs. + +We had issues where our declaration context when finding types was +incorrectly calculated where a type in a namepace, and a type in a +function that was also in the same namespace would match a lookup. For +example: + +namespace a { + struct Foo { +int foo; + }; + + unsigned foo() { +typedef unsigned Foo; +Foo foo = 12; +return foo; + } +} // namespace a + + +Previously LLDB would calculate the declaration context of "a::Foo" +correctly, but incorrectly calculate the declaration context of "Foo" +from within the foo() function as "a::Foo". Adding tests to ensure this +works correctly. +""" +self.build() +target = self.createTestTarget() +exe_module = target.GetModuleAtIndex(0) +self.assertTrue(exe_module.IsValid()) +# Test the SBTarget and SBModule APIs for FindFirstType +for api in [target, exe_module]: +# We should find the "a::Foo" but not the "Foo" type in the function +types = api.FindTypes("a::Foo") +self.assertEqual(types.GetSize(), 1) +type_str0 = str(types.GetTypeAtIndex(0)) +self.assertIn('struct Foo', type_str0) + +# When we search by type basename, we should find any type whose +# basename matches "Foo", so "a::Foo" and the "Foo" type in the +# function. +types = api.FindTypes("Foo") +self.assertEqual(types.GetSize(), 2) +type_str0 = str(types.GetTypeAtIndex(0)) +type_str1 = str(types.GetTypeAtIndex(1)) +# We don't know which order the types will come back as, so +if 'struct Foo' in type_str0: +self.assertIn('typedef Foo', type_str1) +else: +self.assertIn('struct Foo', type_str1) clayborg wrote: I believe it might, I will try it https://github.com/llvm/llvm-project/pull/94846 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix type lookup bug where wrong decl context was being used for a DIE. (PR #94846)
@@ -0,0 +1,69 @@ +""" clayborg wrote: I can do that. I have a DWARF generator that I wrote in python. https://github.com/llvm/llvm-project/pull/94846 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
https://github.com/bulbazord approved this pull request. https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1794,8 +1802,35 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): result.SetError(str(e)) return +# To avoid breaking existing users, we should keep supporting legacy flags +# even if we don't use them / advertise them anymore. +if not options.mode: +if options.batch: +options.mode = CrashLogLoadingMode.batch +else: +options.mode = CrashLogLoadingMode.interactive medismailben wrote: It's illegal to have both `batch` & `interactive` and `argparse` will prevent you from doing anything. https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1821,31 +1856,24 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): print(debugger.GetVersionString()) return -if options.debug: -print("command_args = %s" % command_args) -print("options", options) -print("args", options.reports) - if options.debug_delay > 0: print("Waiting %u seconds for debugger to attach..." % options.debug_delay) time.sleep(options.debug_delay) error = lldb.SBError() def should_run_in_interactive_mode(options, ci): -if options.interactive: +if options.mode == CrashLogLoadingMode.interactive: bulbazord wrote: I guess I'm somewhat confused by the purpose of this function... The only way `options.mode` is ever not interactive is if it's explicitly set by the user to be something else right? Why might we want to ignore that? https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1794,8 +1802,35 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): result.SetError(str(e)) return +# To avoid breaking existing users, we should keep supporting legacy flags +# even if we don't use them / advertise them anymore. +if not options.mode: +if options.batch: +options.mode = CrashLogLoadingMode.batch +else: +options.mode = CrashLogLoadingMode.interactive bulbazord wrote: Can you detect both `options.batch` and `options.interactive` being specified at the same time? I assume whichever is listed first will get selected... but I would assume we'd want to add something that prevents you from choosing both. https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
https://github.com/bulbazord commented: LGTM in general, a few more comments but otherwise this is looking pretty good https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
https://github.com/bulbazord edited https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][NFC] Add sink block to flow CFG in profile inference (PR #95047)
https://github.com/shawbyoung reopened https://github.com/llvm/llvm-project/pull/95047 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
https://github.com/medismailben updated https://github.com/llvm/llvm-project/pull/94575 >From fd69e8f2bb83443b381dd11ebddac33676d5fdf3 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 10 Jun 2024 15:11:25 -0700 Subject: [PATCH] [lldb/crashlog] Make interactive mode the new default This patch makes interactive mode as the default when using the crashlog command. It replaces the existing `-i|--interactive` flag with a new `-m|--mode` option, that can either be `interactive` or `batch`. By default, when the option is not explicitely set by the user, the interactive mode is selected, however, lldb will fallback to batch mode if the command interpreter is not interactive or if stdout is not a tty. This also adds some railguards to prevent users from using interactive only options with the batch mode and updates the tests accordingly. rdar://97801509 Differential Revision: https://reviews.llvm.org/D141658 Signed-off-by: Med Ismail Bennani --- lldb/examples/python/crashlog.py | 124 +++--- .../Python/Crashlog/altered_threadState.test | 2 +- .../Python/Crashlog/json.test | 6 +- .../Python/Crashlog/no_threadState.test | 2 +- .../skipped_status_interactive_crashlog.test | 2 +- .../Python/Crashlog/text.test | 2 +- 6 files changed, 83 insertions(+), 55 deletions(-) diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py index 1c0d717ce455c..b77a30c4ec867 100755 --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -31,6 +31,7 @@ import concurrent.futures import contextlib import datetime +import enum import json import os import platform @@ -45,7 +46,6 @@ import time import uuid - print_lock = threading.RLock() try: @@ -1582,9 +1582,12 @@ def synchronous(debugger): debugger.RunCommandInterpreter(True, False, run_options, 0, False, True) -def CreateSymbolicateCrashLogOptions( -command_name, description, add_interactive_options -): +class CrashLogLoadingMode(str, enum.Enum): +batch = "batch" +interactive = "interactive" + + +def CreateSymbolicateCrashLogOptions(command_name, description): usage = "crashlog [options] [FILE ...]" arg_parser = argparse.ArgumentParser( description=description, @@ -1600,6 +1603,12 @@ def CreateSymbolicateCrashLogOptions( help="crash report(s) to symbolicate", ) +arg_parser.add_argument( +"-m", +"--mode", +choices=[mode.value for mode in CrashLogLoadingMode], +help="change how the symbolicated process and threads are displayed to the user (default: interactive)", +) arg_parser.add_argument( "--version", "-V", @@ -1736,36 +1745,35 @@ def CreateSymbolicateCrashLogOptions( help=argparse.SUPPRESS, default=False, ) -if add_interactive_options: -arg_parser.add_argument( -"-i", -"--interactive", -action="store_true", -help="parse a crash log and load it in a ScriptedProcess", -default=False, -) -arg_parser.add_argument( -"-b", -"--batch", -action="store_true", -help="dump symbolicated stackframes without creating a debug session", -default=True, -) -arg_parser.add_argument( -"--target", -"-t", -dest="target_path", -help="the target binary path that should be used for interactive crashlog (optional)", -default=None, -) -arg_parser.add_argument( -"--skip-status", -"-s", -dest="skip_status", -action="store_true", -help="prevent the interactive crashlog to dump the process status and thread backtrace at launch", -default=False, -) +arg_parser.add_argument( +"--target", +"-t", +dest="target_path", +help="the target binary path that should be used for interactive crashlog (optional)", +default=None, +) +arg_parser.add_argument( +"--skip-status", +"-s", +dest="skip_status", +action="store_true", +help="prevent the interactive crashlog to dump the process status and thread backtrace at launch", +default=False, +) +legacy_group = arg_parser.add_mutually_exclusive_group() +legacy_group.add_argument( +"-i", +"--interactive", +action="store_true", +help=argparse.SUPPRESS, +) +legacy_group.add_argument( +"-b", +"--batch", +action="store_true", +help=argparse.SUPPRESS, +) + return arg_parser @@ -1778,7 +1786,7 @@ def CrashLogOptionParser(): created that has all of the shared libraries loaded at the load addresses found in the crash log file. This allows you to explore the
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1794,8 +1803,36 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): result.SetError(str(e)) return +# To avoid breaking existing users, we should keep supporting legacy flags +# even if we don't use them / advertise them anymore. +if options.interactive: +options.mode = CrashLogLoadingMode.interactive +elif options.batch: +options.mode = CrashLogLoadingMode.batch + +if ( +options.mode medismailben wrote: Oversight. https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1794,8 +1803,36 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): result.SetError(str(e)) return +# To avoid breaking existing users, we should keep supporting legacy flags +# even if we don't use them / advertise them anymore. +if options.interactive: +options.mode = CrashLogLoadingMode.interactive +elif options.batch: +options.mode = CrashLogLoadingMode.batch medismailben wrote: You can't do `-i -b` (or vice versa) because they're in a mutually exclusive group. To answer the first part of the question, we set `options.mode` here because it's the main "source of truth", so if you did `--mode interactive -b` we would technically override the mode to batch. https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1821,31 +1858,24 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): print(debugger.GetVersionString()) return -if options.debug: -print("command_args = %s" % command_args) -print("options", options) -print("args", options.reports) - if options.debug_delay > 0: print("Waiting %u seconds for debugger to attach..." % options.debug_delay) time.sleep(options.debug_delay) error = lldb.SBError() def should_run_in_interactive_mode(options, ci): -if options.interactive: +if options.mode: bulbazord wrote: When is this ever false? https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1794,8 +1803,36 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): result.SetError(str(e)) return +# To avoid breaking existing users, we should keep supporting legacy flags +# even if we don't use them / advertise them anymore. +if options.interactive: +options.mode = CrashLogLoadingMode.interactive +elif options.batch: +options.mode = CrashLogLoadingMode.batch bulbazord wrote: Might be a good place to check if `options.mode` was set before `options.interactive` and/or `options.batch`? What happens if I do something like `-m interactive -i -b`? https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
@@ -1794,8 +1803,36 @@ def SymbolicateCrashLogs(debugger, command_args, result, is_command): result.SetError(str(e)) return +# To avoid breaking existing users, we should keep supporting legacy flags +# even if we don't use them / advertise them anymore. +if options.interactive: +options.mode = CrashLogLoadingMode.interactive +elif options.batch: +options.mode = CrashLogLoadingMode.batch + +if ( +options.mode bulbazord wrote: Isn't `options.mode` always set to interactive? It defaults to that up in the argparse code, so is this check necessary? https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
https://github.com/medismailben updated https://github.com/llvm/llvm-project/pull/94575 >From f00c33948310576668bc886415cf98dbd1ab97be Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 10 Jun 2024 14:54:36 -0700 Subject: [PATCH] [lldb/crashlog] Make interactive mode the new default This patch makes interactive mode as the default when using the crashlog command. It replaces the existing `-i|--interactive` flag with a new `-m|--mode` option, that can either be `interactive` or `batch`. By default, when the option is not explicitely set by the user, the interactive mode is selected, however, lldb will fallback to batch mode if the command interpreter is not interactive or if stdout is not a tty. This also adds some railguards to prevent users from using interactive only options with the batch mode and updates the tests accordingly. rdar://97801509 Differential Revision: https://reviews.llvm.org/D141658 Signed-off-by: Med Ismail Bennani --- lldb/examples/python/crashlog.py | 126 +++--- .../Python/Crashlog/altered_threadState.test | 2 +- .../Python/Crashlog/json.test | 6 +- .../Python/Crashlog/no_threadState.test | 2 +- .../skipped_status_interactive_crashlog.test | 2 +- .../Python/Crashlog/text.test | 2 +- 6 files changed, 85 insertions(+), 55 deletions(-) diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py index 1c0d717ce455c..18f1bbb818bf2 100755 --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -31,6 +31,7 @@ import concurrent.futures import contextlib import datetime +import enum import json import os import platform @@ -45,7 +46,6 @@ import time import uuid - print_lock = threading.RLock() try: @@ -1582,9 +1582,12 @@ def synchronous(debugger): debugger.RunCommandInterpreter(True, False, run_options, 0, False, True) -def CreateSymbolicateCrashLogOptions( -command_name, description, add_interactive_options -): +class CrashLogLoadingMode(str, enum.Enum): +batch = "batch" +interactive = "interactive" + + +def CreateSymbolicateCrashLogOptions(command_name, description): usage = "crashlog [options] [FILE ...]" arg_parser = argparse.ArgumentParser( description=description, @@ -1600,6 +1603,13 @@ def CreateSymbolicateCrashLogOptions( help="crash report(s) to symbolicate", ) +arg_parser.add_argument( +"-m", +"--mode", +choices=[mode.value for mode in CrashLogLoadingMode], +help="change how the symbolicated process and threads are displayed to the user", +default=CrashLogLoadingMode.interactive, +) arg_parser.add_argument( "--version", "-V", @@ -1736,36 +1746,35 @@ def CreateSymbolicateCrashLogOptions( help=argparse.SUPPRESS, default=False, ) -if add_interactive_options: -arg_parser.add_argument( -"-i", -"--interactive", -action="store_true", -help="parse a crash log and load it in a ScriptedProcess", -default=False, -) -arg_parser.add_argument( -"-b", -"--batch", -action="store_true", -help="dump symbolicated stackframes without creating a debug session", -default=True, -) -arg_parser.add_argument( -"--target", -"-t", -dest="target_path", -help="the target binary path that should be used for interactive crashlog (optional)", -default=None, -) -arg_parser.add_argument( -"--skip-status", -"-s", -dest="skip_status", -action="store_true", -help="prevent the interactive crashlog to dump the process status and thread backtrace at launch", -default=False, -) +arg_parser.add_argument( +"--target", +"-t", +dest="target_path", +help="the target binary path that should be used for interactive crashlog (optional)", +default=None, +) +arg_parser.add_argument( +"--skip-status", +"-s", +dest="skip_status", +action="store_true", +help="prevent the interactive crashlog to dump the process status and thread backtrace at launch", +default=False, +) +legacy_group = arg_parser.add_mutually_exclusive_group() +legacy_group.add_argument( +"-i", +"--interactive", +action="store_true", +help=argparse.SUPPRESS, +) +legacy_group.add_argument( +"-b", +"--batch", +action="store_true", +help=argparse.SUPPRESS, +) + return arg_parser @@ -1778,7 +1787,7 @@ def CrashLogOptionParser(): created that has all of the shared libraries loaded at the load addresses found in the crash log file. This
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
medismailben wrote: Closed this by mistake. https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
https://github.com/medismailben updated https://github.com/llvm/llvm-project/pull/94575 >From bc3292a4cecdff503d5123a8dffe4ff32aff814d Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 10 Jun 2024 14:53:29 -0700 Subject: [PATCH] [lldb/crashlog] Make interactive mode the new default This patch makes interactive mode as the default when using the crashlog command. It replaces the existing `-i|--interactive` flag with a new `-m|--mode` option, that can either be `interactive` or `batch`. By default, when the option is not explicitely set by the user, the interactive mode is selected, however, lldb will fallback to batch mode if the command interpreter is not interactive or if stdout is not a tty. This also adds some railguards to prevent users from using interactive only options with the batch mode and updates the tests accordingly. rdar://97801509 Differential Revision: https://reviews.llvm.org/D141658 Signed-off-by: Med Ismail Bennani --- lldb/examples/python/crashlog.py | 125 +++--- .../Python/Crashlog/altered_threadState.test | 2 +- .../Python/Crashlog/json.test | 6 +- .../Python/Crashlog/no_threadState.test | 2 +- .../skipped_status_interactive_crashlog.test | 2 +- .../Python/Crashlog/text.test | 2 +- 6 files changed, 85 insertions(+), 54 deletions(-) diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py index 1c0d717ce455c..52c529fa6f3dd 100755 --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -31,6 +31,7 @@ import concurrent.futures import contextlib import datetime +import enum import json import os import platform @@ -45,7 +46,6 @@ import time import uuid - print_lock = threading.RLock() try: @@ -1582,9 +1582,12 @@ def synchronous(debugger): debugger.RunCommandInterpreter(True, False, run_options, 0, False, True) -def CreateSymbolicateCrashLogOptions( -command_name, description, add_interactive_options -): +class CrashLogLoadingMode(str, enum.Enum): +batch = "batch" +interactive = "interactive" + + +def CreateSymbolicateCrashLogOptions(command_name, description): usage = "crashlog [options] [FILE ...]" arg_parser = argparse.ArgumentParser( description=description, @@ -1600,6 +1603,13 @@ def CreateSymbolicateCrashLogOptions( help="crash report(s) to symbolicate", ) +arg_parser.add_argument( +"-m", +"--mode", +choices=[mode.value for mode in CrashLogLoadingMode], +help="change how the symbolicated process and threads are displayed to the user", +default=CrashLogLoadingMode.interactive, +) arg_parser.add_argument( "--version", "-V", @@ -1736,36 +1746,35 @@ def CreateSymbolicateCrashLogOptions( help=argparse.SUPPRESS, default=False, ) -if add_interactive_options: -arg_parser.add_argument( -"-i", -"--interactive", -action="store_true", -help="parse a crash log and load it in a ScriptedProcess", -default=False, -) -arg_parser.add_argument( -"-b", -"--batch", -action="store_true", -help="dump symbolicated stackframes without creating a debug session", -default=True, -) -arg_parser.add_argument( -"--target", -"-t", -dest="target_path", -help="the target binary path that should be used for interactive crashlog (optional)", -default=None, -) -arg_parser.add_argument( -"--skip-status", -"-s", -dest="skip_status", -action="store_true", -help="prevent the interactive crashlog to dump the process status and thread backtrace at launch", -default=False, -) +arg_parser.add_argument( +"--target", +"-t", +dest="target_path", +help="the target binary path that should be used for interactive crashlog (optional)", +default=None, +) +arg_parser.add_argument( +"--skip-status", +"-s", +dest="skip_status", +action="store_true", +help="prevent the interactive crashlog to dump the process status and thread backtrace at launch", +default=False, +) +legacy_group = arg_parser.add_mutually_exclusive_group() +legacy_group.add_argument( +"-i", +"--interactive", +action="store_true", +help=argparse.SUPPRESS, +) +legacy_group.add_argument( +"-b", +"--batch", +action="store_true", +help=argparse.SUPPRESS, +) + return arg_parser @@ -1778,7 +1787,7 @@ def CrashLogOptionParser(): created that has all of the shared libraries loaded at the load addresses found in the crash log file. This
[Lldb-commits] [lldb] [lldb/crashlog] Make interactive mode the new default (PR #94575)
https://github.com/medismailben reopened https://github.com/llvm/llvm-project/pull/94575 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][NFC] Add sink block to flow CFG in profile inference (PR #95049)
https://github.com/shawbyoung closed https://github.com/llvm/llvm-project/pull/95049 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][NFC] Add sink block to flow CFG in profile inference (PR #95049)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/95049 - **Rebase: [Facebook] Add clang driver options to test debug info and BOLT** - **Rebase: [Facebook] [MC] Introduce NeverAlign fragment type** - **[BOLT] Fix ValidateMemRefs** - **[BOLT][NFC] Add sink block to flow CFG in profile inference** >From c771a162fe79eeaee285a169e7611609f529107d Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Tue, 1 Jun 2021 11:37:41 -0700 Subject: [PATCH 1/4] Rebase: [Facebook] Add clang driver options to test debug info and BOLT Summary: This is an essential piece of infrastructure for us to be continuously testing debug info with BOLT. We can't only make changes to a test repo because we need to change debuginfo tests to call BOLT, hence, this diff needs to sit in our opensource repo. But when upstreaming to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming, we need to git diff and check all folders that are being modified by our commits and discard this one (and leave as an internal diff). To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON. Then run check-lldb and check-debuginfo. Manual rebase conflict history: https://phabricator.intern.facebook.com/D29205224 https://phabricator.intern.facebook.com/D29564078 https://phabricator.intern.facebook.com/D33289118 https://phabricator.intern.facebook.com/D34957174 https://phabricator.intern.facebook.com/D35317341 Test Plan: tested locally Configured with: -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests" -DLLVM_TEST_BOLT=ON Ran test suite with: ninja check-debuginfo ninja check-lldb Reviewers: maks, #llvm-bolt Reviewed By: maks Subscribers: ayermolo, phabricatorlinter Differential Revision: https://phabricator.intern.facebook.com/D46256657 Tasks: T92898286 --- clang/include/clang/Driver/Options.td | 4 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++ cross-project-tests/lit.cfg.py | 14 - cross-project-tests/lit.site.cfg.py.in | 4 lldb/test/API/lit.cfg.py | 5 + lldb/test/API/lit.site.cfg.py.in | 8 +++ lldb/test/Shell/helper/toolchain.py| 5 + lldb/test/Shell/lit.site.cfg.py.in | 9 llvm/CMakeLists.txt| 4 9 files changed, 81 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1637a114fcce1..082ca027261b0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5461,6 +5461,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, MarshallingInfoFlag>; def pipe : Flag<["-", "--"], "pipe">, HelpText<"Use pipes between commands, when possible">; +// Facebook T92898286 +def post_link_optimize : Flag<["--"], "post-link-optimize">, + HelpText<"Apply post-link optimizations using BOLT">; +// End Facebook T92898286 def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">; def prebind : Flag<["-"], "prebind">; def preload : Flag<["-"], "preload">; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index b141e5f2adfab..f7611af5763ab 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation , const JobAction , } } + // Facebook T92898286 + if (Args.hasArg(options::OPT_post_link_optimize)) +CmdArgs.push_back("-q"); + // End Facebook T92898286 + Args.AddAllArgs(CmdArgs, options::OPT_T); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs, Output)); + // Facebook T92898286 + if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename()) +return; + + const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv")); + ArgStringList MoveCmdArgs; + MoveCmdArgs.push_back(Output.getFilename()); + const char *PreBoltBin = + Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt"); + MoveCmdArgs.push_back(PreBoltBin); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + MvExec, MoveCmdArgs, std::nullopt)); + + ArgStringList BoltCmdArgs; + const char *BoltExec = + Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt")); + BoltCmdArgs.push_back(PreBoltBin); + BoltCmdArgs.push_back("-reorder-blocks=reverse"); + BoltCmdArgs.push_back("-update-debug-sections"); + BoltCmdArgs.push_back("-o"); + BoltCmdArgs.push_back(Output.getFilename()); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + BoltExec, BoltCmdArgs, std::nullopt)); + // End
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][NFC] Add sink block to flow CFG in profile inference (PR #95047)
https://github.com/shawbyoung closed https://github.com/llvm/llvm-project/pull/95047 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][NFC] Add sink block to flow CFG in profile inference (PR #95047)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95047 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][NFC] Add sink block to flow CFG in profile inference (PR #95047)
https://github.com/shawbyoung edited https://github.com/llvm/llvm-project/pull/95047 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] shawbyoung/BOLT/constructing sink block in stale profile matching (PR #95047)
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/95047 - **Rebase: [Facebook] Add clang driver options to test debug info and BOLT** - **Rebase: [Facebook] [MC] Introduce NeverAlign fragment type** - **[BOLT] Fix ValidateMemRefs** - **[BOLT][NFC] Add sink block to flow CFG in profile inference** >From c771a162fe79eeaee285a169e7611609f529107d Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Tue, 1 Jun 2021 11:37:41 -0700 Subject: [PATCH 1/4] Rebase: [Facebook] Add clang driver options to test debug info and BOLT Summary: This is an essential piece of infrastructure for us to be continuously testing debug info with BOLT. We can't only make changes to a test repo because we need to change debuginfo tests to call BOLT, hence, this diff needs to sit in our opensource repo. But when upstreaming to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming, we need to git diff and check all folders that are being modified by our commits and discard this one (and leave as an internal diff). To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON. Then run check-lldb and check-debuginfo. Manual rebase conflict history: https://phabricator.intern.facebook.com/D29205224 https://phabricator.intern.facebook.com/D29564078 https://phabricator.intern.facebook.com/D33289118 https://phabricator.intern.facebook.com/D34957174 https://phabricator.intern.facebook.com/D35317341 Test Plan: tested locally Configured with: -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests" -DLLVM_TEST_BOLT=ON Ran test suite with: ninja check-debuginfo ninja check-lldb Reviewers: maks, #llvm-bolt Reviewed By: maks Subscribers: ayermolo, phabricatorlinter Differential Revision: https://phabricator.intern.facebook.com/D46256657 Tasks: T92898286 --- clang/include/clang/Driver/Options.td | 4 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++ cross-project-tests/lit.cfg.py | 14 - cross-project-tests/lit.site.cfg.py.in | 4 lldb/test/API/lit.cfg.py | 5 + lldb/test/API/lit.site.cfg.py.in | 8 +++ lldb/test/Shell/helper/toolchain.py| 5 + lldb/test/Shell/lit.site.cfg.py.in | 9 llvm/CMakeLists.txt| 4 9 files changed, 81 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1637a114fcce1..082ca027261b0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5461,6 +5461,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, MarshallingInfoFlag>; def pipe : Flag<["-", "--"], "pipe">, HelpText<"Use pipes between commands, when possible">; +// Facebook T92898286 +def post_link_optimize : Flag<["--"], "post-link-optimize">, + HelpText<"Apply post-link optimizations using BOLT">; +// End Facebook T92898286 def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">; def prebind : Flag<["-"], "prebind">; def preload : Flag<["-"], "preload">; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index b141e5f2adfab..f7611af5763ab 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation , const JobAction , } } + // Facebook T92898286 + if (Args.hasArg(options::OPT_post_link_optimize)) +CmdArgs.push_back("-q"); + // End Facebook T92898286 + Args.AddAllArgs(CmdArgs, options::OPT_T); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs, Output)); + // Facebook T92898286 + if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename()) +return; + + const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv")); + ArgStringList MoveCmdArgs; + MoveCmdArgs.push_back(Output.getFilename()); + const char *PreBoltBin = + Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt"); + MoveCmdArgs.push_back(PreBoltBin); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + MvExec, MoveCmdArgs, std::nullopt)); + + ArgStringList BoltCmdArgs; + const char *BoltExec = + Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt")); + BoltCmdArgs.push_back(PreBoltBin); + BoltCmdArgs.push_back("-reorder-blocks=reverse"); + BoltCmdArgs.push_back("-update-debug-sections"); + BoltCmdArgs.push_back("-o"); + BoltCmdArgs.push_back(Output.getFilename()); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + BoltExec, BoltCmdArgs, std::nullopt)); + // End
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -0,0 +1,21 @@ +#include + +int main() { + constexpr char SINGLE_INSTANCE_STRING[] = "there_is_only_one_of_me"; + constexpr size_t single_instance_size = sizeof(SINGLE_INSTANCE_STRING) + 1; + char *single_instance = new char[single_instance_size]; + strcpy(single_instance, SINGLE_INSTANCE_STRING); clayborg wrote: So we don't need lines 5-7 if we want to search the thread stack. You can make a local variable that points to this buffer to make sure it is used and stays in the program: ``` const char *stack_string_ptr = SINGLE_INSTANCE_STRING; ``` https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -0,0 +1,31 @@ +import lldb + +SINGLE_INSTANCE_PATTERN = "there_is_only_one_of_me" +DOUBLE_INSTANCE_PATTERN = "there_is_exactly_two_of_me" + + +def GetAddressRanges(test_base): clayborg wrote: Here you can just get the current thread's stack pointer for "there_is_only_one_of_me" and then get its region, and using the SBValue for "str1" and "str2" (see changes to the test program below), you can extract the pointer to the heap copy, and then use that address region. https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -0,0 +1,21 @@ +#include + +int main() { + constexpr char SINGLE_INSTANCE_STRING[] = "there_is_only_one_of_me"; clayborg wrote: If you take constexpr off of here, you can create the variable on the stack, and then just use the memory region for the SP of the current thread to find the region? https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
https://github.com/clayborg edited https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -0,0 +1,21 @@ +#include + +int main() { + constexpr char SINGLE_INSTANCE_STRING[] = "there_is_only_one_of_me"; + constexpr size_t single_instance_size = sizeof(SINGLE_INSTANCE_STRING) + 1; + char *single_instance = new char[single_instance_size]; + strcpy(single_instance, SINGLE_INSTANCE_STRING); + + constexpr char DOUBLE_INSTANCE_STRING[] = "there_is_exactly_two_of_me"; + constexpr size_t double_instance_size = sizeof(DOUBLE_INSTANCE_STRING) + 1; + char *double_instance = new char[double_instance_size]; + char *double_instance_copy = new char[double_instance_size]; + strcpy(double_instance, DOUBLE_INSTANCE_STRING); + strcpy(double_instance_copy, DOUBLE_INSTANCE_STRING); clayborg wrote: might be easier to use std::string here? ``` std::string str1("there_is_exactly_two_of_me"); std::string str2("there_is_exactly_two_of_me"); ``` As long as more that 22 bytes are in the std::string, the string will live on the heap. Then you don't need to manually call strcpy and/or free it later. https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status ) { } } +void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, + AddressRanges , size_t alignment, + size_t max_count) { + // Inputs are already validated in FindInMemory() functions. + assert(buf != nullptr); + assert(size > 0); + assert(alignment > 0); + assert(max_count > 0); + assert(start_addr != LLDB_INVALID_ADDRESS); + assert(end_addr != LLDB_INVALID_ADDRESS); + assert(start_addr < end_addr); + + lldb::addr_t start = start_addr; + while (matches.size() < max_count && (start + size) < end_addr) { +const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size); +if (found_addr == LLDB_INVALID_ADDRESS) + break; +matches.emplace_back(found_addr, size); +start = found_addr + alignment; + } +} + +AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ) { + AddressRanges matches; + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return matches; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); +return matches; + } + if (ranges.empty()) { +error.SetErrorStringWithFormat("ranges in empty"); +return matches; + } + if (alignment == 0) { +error.SetErrorStringWithFormat( +"invalid alignment %zu, must be greater than 0", alignment); +return matches; + } + if (max_count == 0) { +error.SetErrorStringWithFormat( +"invalid max_count %zu, must be greater than 0", max_count); clayborg wrote: "max_count must be greater than zero" https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status ) { } } +void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, + AddressRanges , size_t alignment, + size_t max_count) { + // Inputs are already validated in FindInMemory() functions. + assert(buf != nullptr); + assert(size > 0); + assert(alignment > 0); + assert(max_count > 0); + assert(start_addr != LLDB_INVALID_ADDRESS); + assert(end_addr != LLDB_INVALID_ADDRESS); + assert(start_addr < end_addr); + + lldb::addr_t start = start_addr; + while (matches.size() < max_count && (start + size) < end_addr) { +const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size); +if (found_addr == LLDB_INVALID_ADDRESS) + break; +matches.emplace_back(found_addr, size); +start = found_addr + alignment; + } +} + +AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ) { + AddressRanges matches; + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return matches; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); clayborg wrote: "buffer size is zero" https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status ) { } } +void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, + AddressRanges , size_t alignment, + size_t max_count) { + // Inputs are already validated in FindInMemory() functions. + assert(buf != nullptr); + assert(size > 0); + assert(alignment > 0); + assert(max_count > 0); + assert(start_addr != LLDB_INVALID_ADDRESS); + assert(end_addr != LLDB_INVALID_ADDRESS); + assert(start_addr < end_addr); + + lldb::addr_t start = start_addr; + while (matches.size() < max_count && (start + size) < end_addr) { +const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size); +if (found_addr == LLDB_INVALID_ADDRESS) + break; +matches.emplace_back(found_addr, size); +start = found_addr + alignment; + } +} + +AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ) { + AddressRanges matches; + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return matches; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); +return matches; + } + if (ranges.empty()) { +error.SetErrorStringWithFormat("ranges in empty"); +return matches; + } + if (alignment == 0) { +error.SetErrorStringWithFormat( +"invalid alignment %zu, must be greater than 0", alignment); clayborg wrote: "alignment must be greater than zero" https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -810,6 +809,65 @@ const char *SBProcess::GetBroadcasterClass() { return ConstString(Process::GetStaticBroadcasterClass()).AsCString(); } +lldb::SBAddressRangeList +SBProcess::FindRangesInMemory(const void *buf, uint64_t size, + SBAddressRangeList , uint32_t alignment, + uint32_t max_matches, SBError ) { + LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error); + + Log *log = GetLog(LLDBLog::Process); + lldb::SBAddressRangeList matches; + + ProcessSP process_sp(GetSP()); + if (!process_sp) { +LLDB_LOGF(log, "SBProcess::%s SBProcess is invalid.", __FUNCTION__); +return matches; + } + Process::StopLocker stop_locker; + if (!stop_locker.TryLock(_sp->GetRunLock())) { +LLDB_LOGF( +log, +"SBProcess::%s Cannot find process in memory while process is running.", +__FUNCTION__); +return matches; + } + std::lock_guard guard( + process_sp->GetTarget().GetAPIMutex()); + matches.m_opaque_up->ref() = process_sp->FindRangesInMemory( + reinterpret_cast(buf), size, ranges.m_opaque_up->ref(), + alignment, max_matches, error.ref()); + return matches; +} + +lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size, + SBAddressRange , uint32_t alignment, + SBError ) { + LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error); + + if (!range.IsValid()) { +error.SetErrorStringWithFormat("range is invalid"); +return LLDB_INVALID_ADDRESS; + } + clayborg wrote: Let the `lldb_private::Process::FindInMemory` handle this error so the error is always consistent instead of duplicating it here. https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status ) { } } +void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, + AddressRanges , size_t alignment, + size_t max_count) { + // Inputs are already validated in FindInMemory() functions. + assert(buf != nullptr); + assert(size > 0); + assert(alignment > 0); + assert(max_count > 0); + assert(start_addr != LLDB_INVALID_ADDRESS); + assert(end_addr != LLDB_INVALID_ADDRESS); + assert(start_addr < end_addr); + + lldb::addr_t start = start_addr; + while (matches.size() < max_count && (start + size) < end_addr) { +const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size); +if (found_addr == LLDB_INVALID_ADDRESS) + break; +matches.emplace_back(found_addr, size); +start = found_addr + alignment; + } +} + +AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ) { + AddressRanges matches; + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return matches; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); +return matches; + } + if (ranges.empty()) { +error.SetErrorStringWithFormat("ranges in empty"); +return matches; + } + if (alignment == 0) { +error.SetErrorStringWithFormat( +"invalid alignment %zu, must be greater than 0", alignment); +return matches; + } + if (max_count == 0) { +error.SetErrorStringWithFormat( +"invalid max_count %zu, must be greater than 0", max_count); +return matches; + } + + Target = GetTarget(); + Log *log = GetLog(LLDBLog::Process); + for (size_t i = 0; i < ranges.size(); ++i) { +if (matches.size() >= max_count) { + break; +} +const AddressRange = ranges[i]; +if (range.IsValid() == false) { + LLDB_LOGF(log, "Process::%s range is invalid", __FUNCTION__); + continue; +} + +const lldb::addr_t start_addr = +range.GetBaseAddress().GetLoadAddress(); +if (start_addr == LLDB_INVALID_ADDRESS) { + LLDB_LOGF(log, +"Process::%s range load start address is invalid, skipping", +__FUNCTION__); clayborg wrote: Remove "Process::%s" from the user facing error string. We should mention we were unable to resolve one or more addresses: ``` if (error.Success()) error.SetErrorStringWithFormat("unable to resolve address range: ...". range...) ``` We will need to get the address range string that looks like "a.out[0x1000-0x2000)" and use that in the error string. https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status ) { } } +void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, + AddressRanges , size_t alignment, + size_t max_count) { + // Inputs are already validated in FindInMemory() functions. + assert(buf != nullptr); + assert(size > 0); + assert(alignment > 0); + assert(max_count > 0); + assert(start_addr != LLDB_INVALID_ADDRESS); + assert(end_addr != LLDB_INVALID_ADDRESS); + assert(start_addr < end_addr); + + lldb::addr_t start = start_addr; + while (matches.size() < max_count && (start + size) < end_addr) { +const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size); +if (found_addr == LLDB_INVALID_ADDRESS) + break; +matches.emplace_back(found_addr, size); +start = found_addr + alignment; + } +} + +AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ) { + AddressRanges matches; + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return matches; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); +return matches; + } + if (ranges.empty()) { +error.SetErrorStringWithFormat("ranges in empty"); +return matches; + } + if (alignment == 0) { +error.SetErrorStringWithFormat( +"invalid alignment %zu, must be greater than 0", alignment); +return matches; + } + if (max_count == 0) { +error.SetErrorStringWithFormat( +"invalid max_count %zu, must be greater than 0", max_count); +return matches; + } + + Target = GetTarget(); + Log *log = GetLog(LLDBLog::Process); + for (size_t i = 0; i < ranges.size(); ++i) { +if (matches.size() >= max_count) { + break; +} +const AddressRange = ranges[i]; +if (range.IsValid() == false) { + LLDB_LOGF(log, "Process::%s range is invalid", __FUNCTION__); + continue; +} + +const lldb::addr_t start_addr = +range.GetBaseAddress().GetLoadAddress(); +if (start_addr == LLDB_INVALID_ADDRESS) { + LLDB_LOGF(log, +"Process::%s range load start address is invalid, skipping", +__FUNCTION__); + continue; +} +const lldb::addr_t end_addr = start_addr + range.GetByteSize(); +DoFindInMemory(start_addr, end_addr, buf, size, matches, alignment, + max_count); + } + error.Clear(); + return matches; +} + +lldb::addr_t Process::FindInMemory(const uint8_t *buf, uint64_t size, + const AddressRange , size_t alignment, + Status ) { + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return LLDB_INVALID_ADDRESS; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); clayborg wrote: "buffer size is zero" https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
https://github.com/clayborg requested changes to this pull request. https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status ) { } } +void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, + AddressRanges , size_t alignment, + size_t max_count) { + // Inputs are already validated in FindInMemory() functions. + assert(buf != nullptr); + assert(size > 0); + assert(alignment > 0); + assert(max_count > 0); + assert(start_addr != LLDB_INVALID_ADDRESS); + assert(end_addr != LLDB_INVALID_ADDRESS); + assert(start_addr < end_addr); + + lldb::addr_t start = start_addr; + while (matches.size() < max_count && (start + size) < end_addr) { +const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size); +if (found_addr == LLDB_INVALID_ADDRESS) + break; +matches.emplace_back(found_addr, size); +start = found_addr + alignment; + } +} + +AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ) { + AddressRanges matches; + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return matches; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); +return matches; + } + if (ranges.empty()) { +error.SetErrorStringWithFormat("ranges in empty"); clayborg wrote: "empty ranges" https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status ) { } } +void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, + AddressRanges , size_t alignment, + size_t max_count) { + // Inputs are already validated in FindInMemory() functions. + assert(buf != nullptr); + assert(size > 0); + assert(alignment > 0); + assert(max_count > 0); + assert(start_addr != LLDB_INVALID_ADDRESS); + assert(end_addr != LLDB_INVALID_ADDRESS); + assert(start_addr < end_addr); + + lldb::addr_t start = start_addr; + while (matches.size() < max_count && (start + size) < end_addr) { +const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size); +if (found_addr == LLDB_INVALID_ADDRESS) + break; +matches.emplace_back(found_addr, size); +start = found_addr + alignment; + } +} + +AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ) { + AddressRanges matches; + if (buf == nullptr) { +error.SetErrorStringWithFormat("buffer is null"); +return matches; + } + if (size == 0) { +error.SetErrorStringWithFormat("size is zero"); +return matches; + } + if (ranges.empty()) { +error.SetErrorStringWithFormat("ranges in empty"); +return matches; + } + if (alignment == 0) { +error.SetErrorStringWithFormat( +"invalid alignment %zu, must be greater than 0", alignment); +return matches; + } + if (max_count == 0) { +error.SetErrorStringWithFormat( +"invalid max_count %zu, must be greater than 0", max_count); +return matches; + } + + Target = GetTarget(); + Log *log = GetLog(LLDBLog::Process); + for (size_t i = 0; i < ranges.size(); ++i) { +if (matches.size() >= max_count) { + break; +} +const AddressRange = ranges[i]; +if (range.IsValid() == false) { + LLDB_LOGF(log, "Process::%s range is invalid", __FUNCTION__); clayborg wrote: Remove the `"Process::%s"` since this is a user facing error. We might want to still fill in the error here with the first error: ``` if (error.Success()) error.SetErrorStringWithFormat("invalid range: ...". range...) ``` But we should keep going and still find matches. We will need to get the address range string that looks like "a.out[0x1000-0x2000)" and use that in the error string. https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
walter-erquinigo wrote: @mbucko , could you request commit access to Chris Latner? ``` We grant commit access to contributors with a track record of submitting high quality patches. If you would like commit access, please send an email to [Chris](mailto:clattner%40llvm.org) with your GitHub username. ``` That would be very helpful in case you break the build bots and want to push a hot fix. https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
mbucko wrote: > Thanks. LGTM! Would you be able to Merge it in? https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
https://github.com/JDevlieghere approved this pull request. Thanks. LGTM! https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
https://github.com/mbucko updated https://github.com/llvm/llvm-project/pull/94494 >From 39c8c9aa1cc45fd4cfd16fe841f65a4d1cb08cf4 Mon Sep 17 00:00:00 2001 From: Miro Bucko Date: Wed, 5 Jun 2024 09:03:38 -0700 Subject: [PATCH] Fix flaky TestDAP_console test. Test Plan: llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py --- .../lldbsuite/test/tools/lldb-dap/dap_server.py | 6 -- .../test/tools/lldb-dap/lldbdap_testcase.py | 6 -- .../API/tools/lldb-dap/attach/TestDAP_attach.py | 10 -- .../tools/lldb-dap/commands/TestDAP_commands.py | 15 --- .../API/tools/lldb-dap/console/TestDAP_console.py | 9 ++--- .../API/tools/lldb-dap/launch/TestDAP_launch.py | 10 -- 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index e2126d67a5fe7..a9eeec1840990 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True): self.output_condition.release() return output -def collect_output(self, category, duration, clear=True): -end_time = time.time() + duration +def collect_output(self, category, timeout_secs, pattern, clear=True): +end_time = time.time() + timeout_secs collected_output = "" while end_time > time.time(): output = self.get_output(category, timeout=0.25, clear=clear) if output: collected_output += output +if pattern is not None and pattern in output: +break return collected_output if collected_output else None def enqueue_recv_packet(self, packet): diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index d56ea5dca14be..600dc2b5fe9bb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -195,8 +195,10 @@ def get_stdout(self, timeout=0.0): def get_console(self, timeout=0.0): return self.dap_server.get_output("console", timeout=timeout) -def collect_console(self, duration): -return self.dap_server.collect_output("console", duration=duration) +def collect_console(self, timeout_secs, pattern=None): +return self.dap_server.collect_output( +"console", timeout_secs=timeout_secs, pattern=pattern +) def get_local_as_int(self, name, threadId=None): value = self.dap_server.get_local_variable_value(name, threadId=threadId) diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py index b3ba69749f673..1dbe00144f352 100644 --- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py +++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py @@ -200,7 +200,10 @@ def test_commands(self): # Get output from the console. This should contain both the # "exitCommands" that were run after the second breakpoint was hit # and the "terminateCommands" due to the debugging session ending -output = self.collect_console(duration=1.0) +output = self.collect_console( +timeout_secs=1.0, +pattern=terminateCommands[0], +) self.verify_commands("exitCommands", output, exitCommands) self.verify_commands("terminateCommands", output, terminateCommands) @@ -235,5 +238,8 @@ def test_terminate_commands(self): # Once it's disconnected the console should contain the # "terminateCommands" self.dap_server.request_disconnect(terminateDebuggee=True) -output = self.collect_console(duration=1.0) +output = self.collect_console( +timeout_secs=1.0, +pattern=terminateCommands[0], +) self.verify_commands("terminateCommands", output, terminateCommands) diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py index 226b9385fe719..e4cf903fc0d11 100644 --- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py +++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py @@ -22,7 +22,10 @@ def test_command_directive_quiet_on_success(self): stopCommands=["?" + command_quiet, command_not_quiet], exitCommands=["?" + command_quiet, command_not_quiet], ) -full_output = self.collect_console(duration=1.0) +full_output = self.collect_console( +timeout_secs=1.0, +pattern=command_not_quiet, +) self.assertNotIn(command_quiet,
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
@@ -337,7 +337,7 @@ def test_commands(self): # Get output from the console. This should contain both the # "exitCommands" that were run after the second breakpoint was hit # and the "terminateCommands" due to the debugging session ending -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) walter-erquinigo wrote: add `terminateCommands` to the pattern https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
@@ -235,5 +235,5 @@ def test_terminate_commands(self): # Once it's disconnected the console should contain the # "terminateCommands" self.dap_server.request_disconnect(terminateDebuggee=True) -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) walter-erquinigo wrote: add `terminateCommands` to the pattern https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
@@ -200,7 +200,7 @@ def test_commands(self): # Get output from the console. This should contain both the # "exitCommands" that were run after the second breakpoint was hit # and the "terminateCommands" due to the debugging session ending -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) walter-erquinigo wrote: add `terminateCommands` to the pattern https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
@@ -47,7 +47,7 @@ def do_test_abort_on_error( postRunCommands=commands if use_post_run_commands else None, expectFailure=True, ) -full_output = self.collect_console(duration=1.0) +full_output = self.collect_console(timeout_secs=1.0) walter-erquinigo wrote: add `settings` to the pattern https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
@@ -75,6 +75,6 @@ def test_command_directive_abort_on_error_attach_commands(self): attachCommands=["?!" + command_quiet, "!" + command_abort_on_error], expectFailure=True, ) -full_output = self.collect_console(duration=1.0) +full_output = self.collect_console(timeout_secs=1.0) walter-erquinigo wrote: add `settings` to the pattern https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
@@ -467,5 +467,5 @@ def test_terminate_commands(self): # Once it's disconnected the console should contain the # "terminateCommands" self.dap_server.request_disconnect(terminateDebuggee=True) -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) walter-erquinigo wrote: add `terminateCommands` to the pattern https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
https://github.com/mbucko updated https://github.com/llvm/llvm-project/pull/95007 >From e5b3bf115ff60e2892ccfae387877c205ec659f9 Mon Sep 17 00:00:00 2001 From: Miro Bucko Date: Tue, 4 Jun 2024 12:01:48 -0700 Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API Test Plan: llvm-lit llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py Reviewers: clayborg Tasks: lldb --- lldb/bindings/python/python-typemaps.swig | 3 +- lldb/include/lldb/API/SBProcess.h | 8 ++ lldb/include/lldb/Core/AddressRangeListImpl.h | 2 + lldb/include/lldb/Target/Process.h| 13 ++ lldb/source/API/SBProcess.cpp | 68 - lldb/source/Target/Process.cpp| 118 +++ .../API/python_api/find_in_memory/Makefile| 3 + .../find_in_memory/TestFindInMemory.py| 100 + .../find_in_memory/TestFindRangesInMemory.py | 136 ++ .../find_in_memory/address_ranges_helper.py | 31 .../API/python_api/find_in_memory/main.cpp| 21 +++ 11 files changed, 497 insertions(+), 6 deletions(-) create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py create mode 100644 lldb/test/API/python_api/find_in_memory/address_ranges_helper.py create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig index 8d4b740e5f35c..923a787e77c88 100644 --- a/lldb/bindings/python/python-typemaps.swig +++ b/lldb/bindings/python/python-typemaps.swig @@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result in a double free. } // For SBProcess::WriteMemory, SBTarget::GetInstructions and SBDebugger::DispatchInput. %typemap(in) (const void *buf, size_t size), - (const void *data, size_t data_len) { + (const void *data, size_t data_len), + (const void *buf, uint64_t size) { if (PythonString::Check($input)) { PythonString str(PyRefType::Borrowed, $input); $1 = (void *)str.GetString().data(); diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index f1b5d1fb92ce2..dc8cd116fd420 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -209,6 +209,14 @@ class LLDB_API SBProcess { lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError ); + lldb::SBAddressRangeList + FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList , + uint32_t alignment, uint32_t max_matches, SBError ); + + lldb::addr_t FindInMemory(const void *buf, uint64_t size, +SBAddressRange , uint32_t alignment, +SBError ); + // Events static lldb::StateType GetStateFromEvent(const lldb::SBEvent ); diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h b/lldb/include/lldb/Core/AddressRangeListImpl.h index 46ebfe73d4d92..777cf81e2b1c3 100644 --- a/lldb/include/lldb/Core/AddressRangeListImpl.h +++ b/lldb/include/lldb/Core/AddressRangeListImpl.h @@ -14,6 +14,7 @@ namespace lldb { class SBBlock; +class SBProcess; } namespace lldb_private { @@ -40,6 +41,7 @@ class AddressRangeListImpl { private: friend class lldb::SBBlock; + friend class lldb::SBProcess; AddressRanges (); diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index eec337c15f7ed..3ac19a74b8b99 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2685,6 +2685,15 @@ void PruneThreadPlans(); lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high, const uint8_t *buf, size_t size); + AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size, + const AddressRanges , + size_t alignment, size_t max_count, + Status ); + + lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size, +const AddressRange , size_t alignment, +Status ); + protected: friend class Trace; @@ -2800,6 +2809,10 @@ void PruneThreadPlans(); virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status ) = 0; + void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr, + const uint8_t *buf, size_t size, AddressRanges , + size_t alignment, size_t max_count); + /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has /// removed non address bits from load_addr. Override this method
[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
@@ -0,0 +1,31 @@ +import lldb + +SINGLE_INSTANCE_PATTERN = "there_is_only_one_of_me" +DOUBLE_INSTANCE_PATTERN = "there_is_exactly_two_of_me" + + +def GetAddressRanges(test_base): +mem_regions = test_base.process.GetMemoryRegions() +test_base.assertTrue(len(mem_regions) > 0, "Make sure there are memory regions") +addr_ranges = lldb.SBAddressRangeList() +for i in range(mem_regions.GetSize()): +region_info = lldb.SBMemoryRegionInfo() +if not mem_regions.GetMemoryRegionAtIndex(i, region_info): +continue +if not (region_info.IsReadable() and region_info.IsWritable()): +continue +if region_info.IsExecutable(): +continue +if not region_info.GetName() or region_info.GetName() != "[heap]": mbucko wrote: The above example doesn't have a name which also satisfies the condition so it should work. I mainly wanted to remove regions such as "[stack]" and "/some/path/lib.o" ... https://github.com/llvm/llvm-project/pull/95007 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
https://github.com/mattweingarten updated https://github.com/llvm/llvm-project/pull/94264 error: too big or took too long to generate ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
https://github.com/mbucko updated https://github.com/llvm/llvm-project/pull/94494 >From 5e92ee56b2b278b3ddad04cfdb1f440d3568389c Mon Sep 17 00:00:00 2001 From: Miro Bucko Date: Wed, 5 Jun 2024 09:03:38 -0700 Subject: [PATCH] Fix flaky TestDAP_console test. Test Plan: llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py --- .../Python/lldbsuite/test/tools/lldb-dap/dap_server.py | 6 -- .../lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py| 6 -- lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py| 4 ++-- .../test/API/tools/lldb-dap/commands/TestDAP_commands.py | 6 +++--- lldb/test/API/tools/lldb-dap/console/TestDAP_console.py | 9 ++--- lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py| 4 ++-- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index e2126d67a5fe7..a9eeec1840990 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True): self.output_condition.release() return output -def collect_output(self, category, duration, clear=True): -end_time = time.time() + duration +def collect_output(self, category, timeout_secs, pattern, clear=True): +end_time = time.time() + timeout_secs collected_output = "" while end_time > time.time(): output = self.get_output(category, timeout=0.25, clear=clear) if output: collected_output += output +if pattern is not None and pattern in output: +break return collected_output if collected_output else None def enqueue_recv_packet(self, packet): diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index d56ea5dca14be..600dc2b5fe9bb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -195,8 +195,10 @@ def get_stdout(self, timeout=0.0): def get_console(self, timeout=0.0): return self.dap_server.get_output("console", timeout=timeout) -def collect_console(self, duration): -return self.dap_server.collect_output("console", duration=duration) +def collect_console(self, timeout_secs, pattern=None): +return self.dap_server.collect_output( +"console", timeout_secs=timeout_secs, pattern=pattern +) def get_local_as_int(self, name, threadId=None): value = self.dap_server.get_local_variable_value(name, threadId=threadId) diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py index b3ba69749f673..17a54d996cea6 100644 --- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py +++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py @@ -200,7 +200,7 @@ def test_commands(self): # Get output from the console. This should contain both the # "exitCommands" that were run after the second breakpoint was hit # and the "terminateCommands" due to the debugging session ending -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) self.verify_commands("exitCommands", output, exitCommands) self.verify_commands("terminateCommands", output, terminateCommands) @@ -235,5 +235,5 @@ def test_terminate_commands(self): # Once it's disconnected the console should contain the # "terminateCommands" self.dap_server.request_disconnect(terminateDebuggee=True) -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) self.verify_commands("terminateCommands", output, terminateCommands) diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py index 226b9385fe719..313ae3685b91a 100644 --- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py +++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py @@ -22,7 +22,7 @@ def test_command_directive_quiet_on_success(self): stopCommands=["?" + command_quiet, command_not_quiet], exitCommands=["?" + command_quiet, command_not_quiet], ) -full_output = self.collect_console(duration=1.0) +full_output = self.collect_console(timeout_secs=1.0) self.assertNotIn(command_quiet, full_output) self.assertIn(command_not_quiet, full_output) @@ -47,7 +47,7 @@ def do_test_abort_on_error( postRunCommands=commands if use_post_run_commands else None,
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Remove old GDB Index functions (PR #95019)
https://github.com/sayhaan updated https://github.com/llvm/llvm-project/pull/95019 >From 2ec98177d6e328f966e7eedb1581ede921fa8e8b Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Tue, 1 Jun 2021 11:37:41 -0700 Subject: [PATCH 1/4] Rebase: [Facebook] Add clang driver options to test debug info and BOLT Summary: This is an essential piece of infrastructure for us to be continuously testing debug info with BOLT. We can't only make changes to a test repo because we need to change debuginfo tests to call BOLT, hence, this diff needs to sit in our opensource repo. But when upstreaming to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming, we need to git diff and check all folders that are being modified by our commits and discard this one (and leave as an internal diff). To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON. Then run check-lldb and check-debuginfo. Manual rebase conflict history: https://phabricator.intern.facebook.com/D29205224 https://phabricator.intern.facebook.com/D29564078 https://phabricator.intern.facebook.com/D33289118 https://phabricator.intern.facebook.com/D34957174 https://phabricator.intern.facebook.com/D35317341 Test Plan: tested locally Configured with: -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests" -DLLVM_TEST_BOLT=ON Ran test suite with: ninja check-debuginfo ninja check-lldb Reviewers: maks, #llvm-bolt Reviewed By: maks Subscribers: ayermolo, phabricatorlinter Differential Revision: https://phabricator.intern.facebook.com/D46256657 Tasks: T92898286 --- clang/include/clang/Driver/Options.td | 4 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++ cross-project-tests/lit.cfg.py | 14 - cross-project-tests/lit.site.cfg.py.in | 4 lldb/test/API/lit.cfg.py | 5 + lldb/test/API/lit.site.cfg.py.in | 8 +++ lldb/test/Shell/helper/toolchain.py| 5 + lldb/test/Shell/lit.site.cfg.py.in | 9 llvm/CMakeLists.txt| 4 9 files changed, 81 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d44faa55c456f..63bb86717bb14 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5483,6 +5483,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, MarshallingInfoFlag>; def pipe : Flag<["-", "--"], "pipe">, HelpText<"Use pipes between commands, when possible">; +// Facebook T92898286 +def post_link_optimize : Flag<["--"], "post-link-optimize">, + HelpText<"Apply post-link optimizations using BOLT">; +// End Facebook T92898286 def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">; def prebind : Flag<["-"], "prebind">; def preload : Flag<["-"], "preload">; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index b141e5f2adfab..f7611af5763ab 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation , const JobAction , } } + // Facebook T92898286 + if (Args.hasArg(options::OPT_post_link_optimize)) +CmdArgs.push_back("-q"); + // End Facebook T92898286 + Args.AddAllArgs(CmdArgs, options::OPT_T); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs, Output)); + // Facebook T92898286 + if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename()) +return; + + const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv")); + ArgStringList MoveCmdArgs; + MoveCmdArgs.push_back(Output.getFilename()); + const char *PreBoltBin = + Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt"); + MoveCmdArgs.push_back(PreBoltBin); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + MvExec, MoveCmdArgs, std::nullopt)); + + ArgStringList BoltCmdArgs; + const char *BoltExec = + Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt")); + BoltCmdArgs.push_back(PreBoltBin); + BoltCmdArgs.push_back("-reorder-blocks=reverse"); + BoltCmdArgs.push_back("-update-debug-sections"); + BoltCmdArgs.push_back("-o"); + BoltCmdArgs.push_back(Output.getFilename()); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + BoltExec, BoltCmdArgs, std::nullopt)); + // End Facebook T92898286 } void tools::gnutools::Assembler::ConstructJob(Compilation , diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py index 774c4eaf4d976..619634578dfe6 100644 --- a/cross-project-tests/lit.cfg.py +++
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Remove old GDB Index functions (PR #95019)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r 77f75b45fd8a4bbc061e85a4432c23b64ca7d4f2...b9273c87b2ae189024b6bb08af5a2ee8ecf26de9 cross-project-tests/lit.cfg.py lldb/test/API/lit.cfg.py lldb/test/Shell/helper/toolchain.py `` View the diff from darker here. ``diff --- cross-project-tests/lit.cfg.py 2024-06-09 08:11:06.00 + +++ cross-project-tests/lit.cfg.py 2024-06-10 18:22:29.919149 + @@ -85,11 +85,14 @@ if not hasattr(config, "clang_src_dir"): config.clang_src_dir = "" # Facebook T92898286 should_test_bolt = get_required_attr(config, "llvm_test_bolt") if should_test_bolt: -llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects), additional_flags=["--post-link-optimize"]) +llvm_config.use_clang( +required=("clang" in config.llvm_enabled_projects), +additional_flags=["--post-link-optimize"], +) else: llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects)) # End Facebook T92898286 if not hasattr(config, "lld_src_dir"): `` https://github.com/llvm/llvm-project/pull/95019 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r f26bc5f0c421c7a01a1a611249dd7483b749bab5...ea050132f653a908eeefecd647431a0ed65e2cc0 lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py lldb/test/API/tools/lldb-dap/console/TestDAP_console.py lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py `` View the diff from darker here. ``diff --- packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 2024-06-10 18:17:24.00 + +++ packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 2024-06-10 18:20:19.439593 + @@ -194,11 +194,13 @@ def get_console(self, timeout=0.0): return self.dap_server.get_output("console", timeout=timeout) def collect_console(self, timeout_secs, pattern=None): -return self.dap_server.collect_output("console", timeout_secs=timeout_secs, pattern=pattern) +return self.dap_server.collect_output( +"console", timeout_secs=timeout_secs, pattern=pattern +) def get_local_as_int(self, name, threadId=None): value = self.dap_server.get_local_variable_value(name, threadId=threadId) # 'value' may have the variable value and summary. # Extract the variable value since summary can have nonnumeric characters. --- test/API/tools/lldb-dap/console/TestDAP_console.py 2024-06-10 18:17:24.00 + +++ test/API/tools/lldb-dap/console/TestDAP_console.py 2024-06-10 18:20:19.569320 + @@ -138,11 +138,13 @@ process = get_subprocess(psutil.Process(os.getpid()), process_name) process.terminate() process.wait() # Get the console output -console_output = self.collect_console(timeout_secs=10.0, pattern="exited with status") +console_output = self.collect_console( +timeout_secs=10.0, pattern="exited with status" +) # Verify the exit status message is printed. self.assertIn( "exited with status = -1 (0x) debugserver died with signal SIGTERM", console_output, @@ -154,11 +156,13 @@ program = self.getBuildArtifact("a.out") self.build_and_launch(program, commandEscapePrefix="") self.continue_to_exit() # Get the console output -console_output = self.collect_console(timeout_secs=10.0, pattern="exited with status") +console_output = self.collect_console( +timeout_secs=10.0, pattern="exited with status" +) # Verify the exit status message is printed. self.assertIn( "exited with status = 0 (0x)", console_output, `` https://github.com/llvm/llvm-project/pull/94494 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Remove old GDB Index functions (PR #95019)
llvmbot wrote: @llvm/pr-subscribers-backend-x86 Author: Sayhaan Siddiqui (sayhaan) Changes Remove old usages of GDB Index functions after replacing them with new ones. --- Patch is 38.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95019.diff 22 Files Affected: - (modified) bolt/include/bolt/Rewrite/DWARFRewriter.h (-11) - (modified) bolt/lib/Core/BinaryEmitter.cpp (+1) - (modified) bolt/lib/Rewrite/DWARFRewriter.cpp (-171) - (modified) clang/include/clang/Driver/Options.td (+4) - (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+29) - (modified) cross-project-tests/lit.cfg.py (+13-1) - (modified) cross-project-tests/lit.site.cfg.py.in (+4) - (modified) lldb/test/API/lit.cfg.py (+5) - (modified) lldb/test/API/lit.site.cfg.py.in (+8) - (modified) lldb/test/Shell/helper/toolchain.py (+5) - (modified) lldb/test/Shell/lit.site.cfg.py.in (+9) - (modified) llvm/CMakeLists.txt (+4) - (modified) llvm/include/llvm/MC/MCFragment.h (+22) - (modified) llvm/include/llvm/MC/MCObjectStreamer.h (+2) - (modified) llvm/include/llvm/MC/MCStreamer.h (+6) - (modified) llvm/lib/MC/MCAssembler.cpp (+81-37) - (modified) llvm/lib/MC/MCExpr.cpp (+2-8) - (modified) llvm/lib/MC/MCFragment.cpp (+12) - (modified) llvm/lib/MC/MCObjectStreamer.cpp (+5) - (modified) llvm/lib/MC/MCStreamer.cpp (+2) - (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+24) - (added) llvm/test/MC/X86/directive-avoid_end_align.s (+208) ``diff diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h b/bolt/include/bolt/Rewrite/DWARFRewriter.h index 3cc9d823c815b..4559ff5ff5159 100644 --- a/bolt/include/bolt/Rewrite/DWARFRewriter.h +++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h @@ -150,9 +150,6 @@ class DWARFRewriter { /// blocks) to be updated. void updateDebugAddressRanges(); - /// Rewrite .gdb_index section if present. - void updateGdbIndexSection(CUOffsetMap , uint32_t NumCUs); - /// DWARFDie contains a pointer to a DIE and hence gets invalidated once the /// embedded DIE is destroyed. This wrapper class stores a DIE internally and /// could be cast to a DWARFDie that is valid even after the initial DIE is @@ -194,14 +191,6 @@ class DWARFRewriter { DwoRangesBase[DWOId] = RangesBase; } - /// Adds an GDBIndexTUEntry if .gdb_index seciton exists. - void addGDBTypeUnitEntry(const GDBIndexTUEntry &); - - /// Returns all entries needed for Types CU list - const GDBIndexTUEntryType () const { -return GDBIndexTUEntryVector; - } - using OverriddenSectionsMap = std::unordered_map; /// Output .dwo files. void writeDWOFiles(DWARFUnit &, const OverriddenSectionsMap &, diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp index 5793963f9b80d..c231fffa0d5ff 100644 --- a/bolt/lib/Core/BinaryEmitter.cpp +++ b/bolt/lib/Core/BinaryEmitter.cpp @@ -487,6 +487,7 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction , FunctionFragment , // This assumes the second instruction in the macro-op pair will get // assigned to its own MCRelaxableFragment. Since all JCC instructions // are relaxable, we should be safe. +Streamer.emitNeverAlignCodeAtEnd(/*Alignment to avoid=*/64, *BC.STI); } if (!EmitCodeOnly) { diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp index 7b62999dfb2b6..04dc7e94e6031 100644 --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -2062,177 +2062,6 @@ void DWARFRewriter::writeDWOFiles( TempOut->keep(); } -void DWARFRewriter::addGDBTypeUnitEntry(const GDBIndexTUEntry &) { - std::lock_guard Lock(DWARFRewriterMutex); - if (!BC.getGdbIndexSection()) -return; - GDBIndexTUEntryVector.emplace_back(Entry); -} - -void DWARFRewriter::updateGdbIndexSection(CUOffsetMap , uint32_t NumCUs) { - if (!BC.getGdbIndexSection()) -return; - - // See https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html - // for .gdb_index section format. - - StringRef GdbIndexContents = BC.getGdbIndexSection()->getContents(); - - const char *Data = GdbIndexContents.data(); - - // Parse the header. - const uint32_t Version = read32le(Data); - if (Version != 7 && Version != 8) { -errs() << "BOLT-ERROR: can only process .gdb_index versions 7 and 8\n"; -exit(1); - } - - // Some .gdb_index generators use file offsets while others use section - // offsets. Hence we can only rely on offsets relative to each other, - // and ignore their absolute values. - const uint32_t CUListOffset = read32le(Data + 4); - const uint32_t CUTypesOffset = read32le(Data + 8); - const uint32_t AddressTableOffset = read32le(Data + 12); - const uint32_t SymbolTableOffset = read32le(Data + 16); - const uint32_t ConstantPoolOffset = read32le(Data + 20); - Data += 24; - - // Map CUs offsets to indices and verify existing index table. - std::map OffsetToIndexMap; - const uint32_t
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Remove old GDB Index functions (PR #95019)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Sayhaan Siddiqui (sayhaan) Changes Remove old usages of GDB Index functions after replacing them with new ones. --- Patch is 38.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95019.diff 22 Files Affected: - (modified) bolt/include/bolt/Rewrite/DWARFRewriter.h (-11) - (modified) bolt/lib/Core/BinaryEmitter.cpp (+1) - (modified) bolt/lib/Rewrite/DWARFRewriter.cpp (-171) - (modified) clang/include/clang/Driver/Options.td (+4) - (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+29) - (modified) cross-project-tests/lit.cfg.py (+13-1) - (modified) cross-project-tests/lit.site.cfg.py.in (+4) - (modified) lldb/test/API/lit.cfg.py (+5) - (modified) lldb/test/API/lit.site.cfg.py.in (+8) - (modified) lldb/test/Shell/helper/toolchain.py (+5) - (modified) lldb/test/Shell/lit.site.cfg.py.in (+9) - (modified) llvm/CMakeLists.txt (+4) - (modified) llvm/include/llvm/MC/MCFragment.h (+22) - (modified) llvm/include/llvm/MC/MCObjectStreamer.h (+2) - (modified) llvm/include/llvm/MC/MCStreamer.h (+6) - (modified) llvm/lib/MC/MCAssembler.cpp (+81-37) - (modified) llvm/lib/MC/MCExpr.cpp (+2-8) - (modified) llvm/lib/MC/MCFragment.cpp (+12) - (modified) llvm/lib/MC/MCObjectStreamer.cpp (+5) - (modified) llvm/lib/MC/MCStreamer.cpp (+2) - (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+24) - (added) llvm/test/MC/X86/directive-avoid_end_align.s (+208) ``diff diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h b/bolt/include/bolt/Rewrite/DWARFRewriter.h index 3cc9d823c815b..4559ff5ff5159 100644 --- a/bolt/include/bolt/Rewrite/DWARFRewriter.h +++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h @@ -150,9 +150,6 @@ class DWARFRewriter { /// blocks) to be updated. void updateDebugAddressRanges(); - /// Rewrite .gdb_index section if present. - void updateGdbIndexSection(CUOffsetMap , uint32_t NumCUs); - /// DWARFDie contains a pointer to a DIE and hence gets invalidated once the /// embedded DIE is destroyed. This wrapper class stores a DIE internally and /// could be cast to a DWARFDie that is valid even after the initial DIE is @@ -194,14 +191,6 @@ class DWARFRewriter { DwoRangesBase[DWOId] = RangesBase; } - /// Adds an GDBIndexTUEntry if .gdb_index seciton exists. - void addGDBTypeUnitEntry(const GDBIndexTUEntry &); - - /// Returns all entries needed for Types CU list - const GDBIndexTUEntryType () const { -return GDBIndexTUEntryVector; - } - using OverriddenSectionsMap = std::unordered_map; /// Output .dwo files. void writeDWOFiles(DWARFUnit &, const OverriddenSectionsMap &, diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp index 5793963f9b80d..c231fffa0d5ff 100644 --- a/bolt/lib/Core/BinaryEmitter.cpp +++ b/bolt/lib/Core/BinaryEmitter.cpp @@ -487,6 +487,7 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction , FunctionFragment , // This assumes the second instruction in the macro-op pair will get // assigned to its own MCRelaxableFragment. Since all JCC instructions // are relaxable, we should be safe. +Streamer.emitNeverAlignCodeAtEnd(/*Alignment to avoid=*/64, *BC.STI); } if (!EmitCodeOnly) { diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp index 7b62999dfb2b6..04dc7e94e6031 100644 --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -2062,177 +2062,6 @@ void DWARFRewriter::writeDWOFiles( TempOut->keep(); } -void DWARFRewriter::addGDBTypeUnitEntry(const GDBIndexTUEntry &) { - std::lock_guard Lock(DWARFRewriterMutex); - if (!BC.getGdbIndexSection()) -return; - GDBIndexTUEntryVector.emplace_back(Entry); -} - -void DWARFRewriter::updateGdbIndexSection(CUOffsetMap , uint32_t NumCUs) { - if (!BC.getGdbIndexSection()) -return; - - // See https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html - // for .gdb_index section format. - - StringRef GdbIndexContents = BC.getGdbIndexSection()->getContents(); - - const char *Data = GdbIndexContents.data(); - - // Parse the header. - const uint32_t Version = read32le(Data); - if (Version != 7 && Version != 8) { -errs() << "BOLT-ERROR: can only process .gdb_index versions 7 and 8\n"; -exit(1); - } - - // Some .gdb_index generators use file offsets while others use section - // offsets. Hence we can only rely on offsets relative to each other, - // and ignore their absolute values. - const uint32_t CUListOffset = read32le(Data + 4); - const uint32_t CUTypesOffset = read32le(Data + 8); - const uint32_t AddressTableOffset = read32le(Data + 12); - const uint32_t SymbolTableOffset = read32le(Data + 16); - const uint32_t ConstantPoolOffset = read32le(Data + 20); - Data += 24; - - // Map CUs offsets to indices and verify existing index table. - std::map OffsetToIndexMap; - const uint32_t CUListSize =
[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Remove old GDB Index functions (PR #95019)
https://github.com/sayhaan created https://github.com/llvm/llvm-project/pull/95019 Remove old usages of GDB Index functions after replacing them with new ones. >From b2fe35ae825dc757ea1daaf49142e789c4a560fc Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Tue, 1 Jun 2021 11:37:41 -0700 Subject: [PATCH 1/4] Rebase: [Facebook] Add clang driver options to test debug info and BOLT Summary: This is an essential piece of infrastructure for us to be continuously testing debug info with BOLT. We can't only make changes to a test repo because we need to change debuginfo tests to call BOLT, hence, this diff needs to sit in our opensource repo. But when upstreaming to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming, we need to git diff and check all folders that are being modified by our commits and discard this one (and leave as an internal diff). To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON. Then run check-lldb and check-debuginfo. Manual rebase conflict history: https://phabricator.intern.facebook.com/D29205224 https://phabricator.intern.facebook.com/D29564078 https://phabricator.intern.facebook.com/D33289118 https://phabricator.intern.facebook.com/D34957174 https://phabricator.intern.facebook.com/D35317341 Test Plan: tested locally Configured with: -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests" -DLLVM_TEST_BOLT=ON Ran test suite with: ninja check-debuginfo ninja check-lldb Reviewers: maks, #llvm-bolt Reviewed By: maks Subscribers: ayermolo, phabricatorlinter Differential Revision: https://phabricator.intern.facebook.com/D46256657 Tasks: T92898286 --- clang/include/clang/Driver/Options.td | 4 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++ cross-project-tests/lit.cfg.py | 14 - cross-project-tests/lit.site.cfg.py.in | 4 lldb/test/API/lit.cfg.py | 5 + lldb/test/API/lit.site.cfg.py.in | 8 +++ lldb/test/Shell/helper/toolchain.py| 5 + lldb/test/Shell/lit.site.cfg.py.in | 9 llvm/CMakeLists.txt| 4 9 files changed, 81 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d44faa55c456f..63bb86717bb14 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5483,6 +5483,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, MarshallingInfoFlag>; def pipe : Flag<["-", "--"], "pipe">, HelpText<"Use pipes between commands, when possible">; +// Facebook T92898286 +def post_link_optimize : Flag<["--"], "post-link-optimize">, + HelpText<"Apply post-link optimizations using BOLT">; +// End Facebook T92898286 def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">; def prebind : Flag<["-"], "prebind">; def preload : Flag<["-"], "preload">; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index b141e5f2adfab..f7611af5763ab 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation , const JobAction , } } + // Facebook T92898286 + if (Args.hasArg(options::OPT_post_link_optimize)) +CmdArgs.push_back("-q"); + // End Facebook T92898286 + Args.AddAllArgs(CmdArgs, options::OPT_T); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs, Output)); + // Facebook T92898286 + if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename()) +return; + + const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv")); + ArgStringList MoveCmdArgs; + MoveCmdArgs.push_back(Output.getFilename()); + const char *PreBoltBin = + Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt"); + MoveCmdArgs.push_back(PreBoltBin); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + MvExec, MoveCmdArgs, std::nullopt)); + + ArgStringList BoltCmdArgs; + const char *BoltExec = + Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt")); + BoltCmdArgs.push_back(PreBoltBin); + BoltCmdArgs.push_back("-reorder-blocks=reverse"); + BoltCmdArgs.push_back("-update-debug-sections"); + BoltCmdArgs.push_back("-o"); + BoltCmdArgs.push_back(Output.getFilename()); + C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), + BoltExec, BoltCmdArgs, std::nullopt)); + // End Facebook T92898286 } void tools::gnutools::Assembler::ConstructJob(Compilation , diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py index
[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)
https://github.com/mbucko updated https://github.com/llvm/llvm-project/pull/94494 >From ea050132f653a908eeefecd647431a0ed65e2cc0 Mon Sep 17 00:00:00 2001 From: Miro Bucko Date: Wed, 5 Jun 2024 09:03:38 -0700 Subject: [PATCH] Fix flaky TestDAP_console test. Test Plan: llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py --- .../Python/lldbsuite/test/tools/lldb-dap/dap_server.py | 6 -- .../lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py | 4 ++-- lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py | 4 ++-- lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py | 6 +++--- lldb/test/API/tools/lldb-dap/console/TestDAP_console.py | 5 ++--- lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index e2126d67a5fe7..a9eeec1840990 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True): self.output_condition.release() return output -def collect_output(self, category, duration, clear=True): -end_time = time.time() + duration +def collect_output(self, category, timeout_secs, pattern, clear=True): +end_time = time.time() + timeout_secs collected_output = "" while end_time > time.time(): output = self.get_output(category, timeout=0.25, clear=clear) if output: collected_output += output +if pattern is not None and pattern in output: +break return collected_output if collected_output else None def enqueue_recv_packet(self, packet): diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index d56ea5dca14be..e3796edb2291d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -195,8 +195,8 @@ def get_stdout(self, timeout=0.0): def get_console(self, timeout=0.0): return self.dap_server.get_output("console", timeout=timeout) -def collect_console(self, duration): -return self.dap_server.collect_output("console", duration=duration) +def collect_console(self, timeout_secs, pattern=None): +return self.dap_server.collect_output("console", timeout_secs=timeout_secs, pattern=pattern) def get_local_as_int(self, name, threadId=None): value = self.dap_server.get_local_variable_value(name, threadId=threadId) diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py index b3ba69749f673..17a54d996cea6 100644 --- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py +++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py @@ -200,7 +200,7 @@ def test_commands(self): # Get output from the console. This should contain both the # "exitCommands" that were run after the second breakpoint was hit # and the "terminateCommands" due to the debugging session ending -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) self.verify_commands("exitCommands", output, exitCommands) self.verify_commands("terminateCommands", output, terminateCommands) @@ -235,5 +235,5 @@ def test_terminate_commands(self): # Once it's disconnected the console should contain the # "terminateCommands" self.dap_server.request_disconnect(terminateDebuggee=True) -output = self.collect_console(duration=1.0) +output = self.collect_console(timeout_secs=1.0) self.verify_commands("terminateCommands", output, terminateCommands) diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py index 226b9385fe719..313ae3685b91a 100644 --- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py +++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py @@ -22,7 +22,7 @@ def test_command_directive_quiet_on_success(self): stopCommands=["?" + command_quiet, command_not_quiet], exitCommands=["?" + command_quiet, command_not_quiet], ) -full_output = self.collect_console(duration=1.0) +full_output = self.collect_console(timeout_secs=1.0) self.assertNotIn(command_quiet, full_output) self.assertIn(command_not_quiet, full_output) @@ -47,7 +47,7 @@ def do_test_abort_on_error( postRunCommands=commands if use_post_run_commands else None,
[Lldb-commits] [lldb] [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (PR #95015)
https://github.com/medismailben closed https://github.com/llvm/llvm-project/pull/95015 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 93b91dd - [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (#95015)
Author: Med Ismail Bennani Date: 2024-06-10T10:49:16-07:00 New Revision: 93b91d031a703cc2f19bbe35e95bc0de6970 URL: https://github.com/llvm/llvm-project/commit/93b91d031a703cc2f19bbe35e95bc0de6970 DIFF: https://github.com/llvm/llvm-project/commit/93b91d031a703cc2f19bbe35e95bc0de6970.diff LOG: [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (#95015) This patch tightens the assert check for the ABISP object in `StopInfoMachException::DeterminePtrauthFailure`. This causes some failure when debugging on a system that doesn't have pointer authentification support, like on Intel for instance. rdar://129401926 Signed-off-by: Med Ismail Bennani Added: Modified: lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp Removed: diff --git a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp index 75504323b4fdf..25cee369d7ee3 100644 --- a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp +++ b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp @@ -92,9 +92,7 @@ bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext _ctx) { Target = *exe_ctx.GetTargetPtr(); Process = *exe_ctx.GetProcessPtr(); - ABISP abi_sp = process.GetABI(); const ArchSpec = target.GetArchitecture(); - assert(abi_sp && "Missing ABI info"); // Check for a ptrauth-enabled target. const bool ptrauth_enabled_target = @@ -110,6 +108,9 @@ bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext _ctx) { strm.Printf("Note: Possible pointer authentication failure detected.\n"); }; + ABISP abi_sp = process.GetABI(); + assert(abi_sp && "Missing ABI info"); + // Check if we have a "brk 0xc47x" trap, where the value that failed to // authenticate is in x16. Address current_address = current_frame->GetFrameCodeAddress(); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (PR #95015)
https://github.com/felipepiovezan approved this pull request. https://github.com/llvm/llvm-project/pull/95015 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix type lookup bug where wrong decl context was being used for a DIE. (PR #94846)
https://github.com/jeffreytan81 approved this pull request. https://github.com/llvm/llvm-project/pull/94846 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (PR #95015)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Med Ismail Bennani (medismailben) Changes This patch tightens the assert check for the ABISP object in `StopInfoMachException::DeterminePtrauthFailure`. This causes some failure when debugging on a system that doesn't have pointer authentification support, like on Intel for instance. rdar://129401926 --- Full diff: https://github.com/llvm/llvm-project/pull/95015.diff 1 Files Affected: - (modified) lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp (+3-2) ``diff diff --git a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp index 75504323b4fdf..25cee369d7ee3 100644 --- a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp +++ b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp @@ -92,9 +92,7 @@ bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext _ctx) { Target = *exe_ctx.GetTargetPtr(); Process = *exe_ctx.GetProcessPtr(); - ABISP abi_sp = process.GetABI(); const ArchSpec = target.GetArchitecture(); - assert(abi_sp && "Missing ABI info"); // Check for a ptrauth-enabled target. const bool ptrauth_enabled_target = @@ -110,6 +108,9 @@ bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext _ctx) { strm.Printf("Note: Possible pointer authentication failure detected.\n"); }; + ABISP abi_sp = process.GetABI(); + assert(abi_sp && "Missing ABI info"); + // Check if we have a "brk 0xc47x" trap, where the value that failed to // authenticate is in x16. Address current_address = current_frame->GetFrameCodeAddress(); `` https://github.com/llvm/llvm-project/pull/95015 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Tighten ABI assert in `StopInfoMachException::DeterminePtrauthFailure` (NFC) (PR #95015)
https://github.com/medismailben created https://github.com/llvm/llvm-project/pull/95015 This patch tightens the assert check for the ABISP object in `StopInfoMachException::DeterminePtrauthFailure`. This causes some failure when debugging on a system that doesn't have pointer authentification support, like on Intel for instance. rdar://129401926 >From 3036bf2704bfa373c57df5f62a57d2296aedc01e Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 10 Jun 2024 10:42:10 -0700 Subject: [PATCH] [lldb] Tighten ABI assert in StopInfoMachException::DeterminePtrauthFailure (NFC) This patch tightens the assert check for the ABISP object in `StopInfoMachException::DeterminePtrauthFailure`. This causes some failure when debugging on a system that doesn't have pointer authentification support, like on Intel for instance. rdar://129401926 Signed-off-by: Med Ismail Bennani --- .../source/Plugins/Process/Utility/StopInfoMachException.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp index 75504323b4fdf..25cee369d7ee3 100644 --- a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp +++ b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp @@ -92,9 +92,7 @@ bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext _ctx) { Target = *exe_ctx.GetTargetPtr(); Process = *exe_ctx.GetProcessPtr(); - ABISP abi_sp = process.GetABI(); const ArchSpec = target.GetArchitecture(); - assert(abi_sp && "Missing ABI info"); // Check for a ptrauth-enabled target. const bool ptrauth_enabled_target = @@ -110,6 +108,9 @@ bool StopInfoMachException::DeterminePtrauthFailure(ExecutionContext _ctx) { strm.Printf("Note: Possible pointer authentication failure detected.\n"); }; + ABISP abi_sp = process.GetABI(); + assert(abi_sp && "Missing ABI info"); + // Check if we have a "brk 0xc47x" trap, where the value that failed to // authenticate is in x16. Address current_address = current_frame->GetFrameCodeAddress(); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits