[Lldb-commits] [lldb] [lldb][windows] refactor null handling in DynamicLoaderWindowsDYLD (PR #200821)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 1 06:46:35 PDT 2026


https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/200821

This patch thightens the null guards.

>From d4e1928dc39f028149b644a8acd997c16dff8fb2 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Mon, 1 Jun 2026 14:44:49 +0100
Subject: [PATCH] [lldb][windows] refactor null handling in
 DynamicLoaderWindowsDYLD

---
 .../Windows-DYLD/DynamicLoaderWindowsDYLD.cpp | 31 ++++++++++++-------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
index 79fb4d46eff41..0c9fe73d4d62c 100644
--- a/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
@@ -139,7 +139,7 @@ void DynamicLoaderWindowsDYLD::DidAttach() {
 
   ModuleSP executable = GetTargetExecutable();
 
-  if (!executable.get())
+  if (!executable)
     return;
 
   // Try to fetch the load address of the file from the process, since there
@@ -168,7 +168,7 @@ void DynamicLoaderWindowsDYLD::DidLaunch() {
   LLDB_LOGF(log, "DynamicLoaderWindowsDYLD::%s()", __FUNCTION__);
 
   ModuleSP executable = GetTargetExecutable();
-  if (!executable.get())
+  if (!executable)
     return;
 
   lldb::addr_t load_addr = GetLoadAddress(executable);
@@ -194,7 +194,11 @@ DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread,
     return ThreadPlanSP();
   }
 
-  uint64_t pc = thread.GetRegisterContext()->GetPC();
+  RegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
+  if (!reg_ctx_sp)
+    return ThreadPlanSP();
+
+  uint64_t pc = reg_ctx_sp->GetPC();
   // Max size of an instruction in x86 is 15 bytes.
   AddressRange range(pc, 2 * 15);
 
@@ -204,10 +208,7 @@ DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread,
     return ThreadPlanSP();
   }
 
-  InstructionList *insn_list = &disassembler_sp->GetInstructionList();
-  if (insn_list == nullptr) {
-    return ThreadPlanSP();
-  }
+  InstructionList &insn_list = disassembler_sp->GetInstructionList();
 
   // First instruction in a x86 Windows trampoline is going to be an indirect
   // jump through the IAT and the next one will be a nop (usually there for
@@ -215,13 +216,19 @@ DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread,
   //     0x70ff4cfc <+956>: jmpl   *0x7100c2a8
   //     0x70ff4d02 <+962>: nop
 
-  auto first_insn = insn_list->GetInstructionAtIndex(0);
-  auto second_insn = insn_list->GetInstructionAtIndex(1);
+  auto first_insn = insn_list.GetInstructionAtIndex(0);
+  auto second_insn = insn_list.GetInstructionAtIndex(1);
 
   ExecutionContext exe_ctx(m_process->GetTarget());
-  if (first_insn == nullptr || second_insn == nullptr ||
-      strcmp(first_insn->GetMnemonic(&exe_ctx), "jmpl") != 0 ||
-      strcmp(second_insn->GetMnemonic(&exe_ctx), "nop") != 0) {
+  if (first_insn == nullptr || second_insn == nullptr) {
+    return ThreadPlanSP();
+  }
+
+  const char *first_mnemonic = first_insn->GetMnemonic(&exe_ctx);
+  const char *second_mnemonic = second_insn->GetMnemonic(&exe_ctx);
+  if (!first_mnemonic || !second_mnemonic ||
+      strcmp(first_mnemonic, "jmpl") != 0 ||
+      strcmp(second_mnemonic, "nop") != 0) {
     return ThreadPlanSP();
   }
 



More information about the lldb-commits mailing list