[Lldb-commits] [lldb] 459cfa5 - [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

2022-07-20 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-20T14:50:48-07:00
New Revision: 459cfa5e94d75b08aa421b79765ba1cd2126c4a4

URL: 
https://github.com/llvm/llvm-project/commit/459cfa5e94d75b08aa421b79765ba1cd2126c4a4
DIFF: 
https://github.com/llvm/llvm-project/commit/459cfa5e94d75b08aa421b79765ba1cd2126c4a4.diff

LOG: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

Improve LLDB reliability by fixing the following "uninitialized variables" 
static code inspection warnings from
scan.coverity.com:

1094796 1095721 1095728 1095737 1095741
1095756 1095779 1095789 1095805 1214552
1229457 1232475 1274006 1274010 1293427
1364800 1364802 1364804 1364812 1364816
1374902 1374909 1384975 1399312 1420451
1431704 1454230 1454554 1454615 1454579
1454594 1454832 1457759 1458696 1461909
1467658 1487814 1487830 1487845

Differential Revision: https://reviews.llvm.org/D130098

Added: 


Modified: 
lldb/include/lldb/Core/EmulateInstruction.h
lldb/include/lldb/DataFormatters/TypeCategory.h
lldb/include/lldb/DataFormatters/TypeSynthetic.h
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Commands/CommandObjectThread.cpp
lldb/source/Commands/CommandObjectType.cpp
lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp
lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
lldb/source/Plugins/Language/ObjC/CFBasicHash.h
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
lldb/source/Plugins/Language/ObjC/NSError.cpp
lldb/source/Plugins/Language/ObjC/NSSet.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h

lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/EmulateInstruction.h 
b/lldb/include/lldb/Core/EmulateInstruction.h
index f50fee095a8bb..e5421e5e91d1a 100644
--- a/lldb/include/lldb/Core/EmulateInstruction.h
+++ b/lldb/include/lldb/Core/EmulateInstruction.h
@@ -179,7 +179,7 @@ class EmulateInstruction : public PluginInterface {
 eInfoTypeISAAndImmediateSigned,
 eInfoTypeISA,
 eInfoTypeNoArgs
-  } InfoType;
+  };
 
   struct Context {
 ContextType type = eContextInvalid;

diff  --git a/lldb/include/lldb/DataFormatters/TypeCategory.h 
b/lldb/include/lldb/DataFormatters/TypeCategory.h
index 2c93059018372..16255f9488bda 100644
--- a/lldb/include/lldb/DataFormatters/TypeCategory.h
+++ b/lldb/include/lldb/DataFormatters/TypeCategory.h
@@ -331,7 +331,7 @@ class TypeCategoryImpl {
 
   std::vector m_languages;
 
-  uint32_t m_enabled_position;
+  uint32_t m_enabled_position = 0;
 
   void Enable(bool value, uint32_t position);
 

diff  --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h 
b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
index 3f58297a529b3..890a6eb4f4487 100644
--- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h
+++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
@@ -266,7 +266,7 @@ class SyntheticChildren {
   uint32_t &GetRevision() { return m_my_revision; }
 
 protected:
-  uint32_t m_my_revision;
+  uint32_t m_my_revision = 0;
   Flags m_flags;
 
 private:

diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index 3c07d19b35b26..ca0384cf9453d 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -275,7 +275,7 @@ class OptionGroupReadMemory : public OptionGroup {
   OptionValueUInt64 m_num_per_line;
   bool m_output_as_binary = false;
   OptionValueString m_view_as_type;
-  bool m_force;
+  bool m_force = false;
   OptionValueUInt64 m_offset;
   OptionValueLanguage m_language_for_type;
 };

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectT

[Lldb-commits] [lldb] 98186de - [LLDB][Reliability] Fix accessing invalid iterator

2022-07-21 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-21T17:39:11-07:00
New Revision: 98186def3f1f6f3862e6c91ca01dfd278ad1929e

URL: 
https://github.com/llvm/llvm-project/commit/98186def3f1f6f3862e6c91ca01dfd278ad1929e
DIFF: 
https://github.com/llvm/llvm-project/commit/98186def3f1f6f3862e6c91ca01dfd278ad1929e.diff

LOG: [LLDB][Reliability] Fix accessing invalid iterator

Using invalidated vector iterator is at best a UB and could crash depending on 
STL implementation.
Fixing via minimal changes to preserve the existing code style.

Coverity warning 1454828  (scan.coverity.com)

Differential Revision: https://reviews.llvm.org/D130312

Added: 


Modified: 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 9a41a11ef5040..832057eb33087 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -610,8 +610,10 @@ bool 
DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress(
 // Also copy over the uuid from the old entry to the removed entry so we
 // can use it to lookup the module in the module list.
 
-ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
-for (pos = m_dyld_image_infos.begin(); pos != end; pos++) {
+bool found = false;
+
+for (ImageInfo::collection::iterator pos = m_dyld_image_infos.begin();
+ pos != m_dyld_image_infos.end(); pos++) {
   if (image_infos[idx].address == (*pos).address) {
 image_infos[idx].uuid = (*pos).uuid;
 
@@ -635,11 +637,12 @@ bool 
DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress(
 // Then remove it from the m_dyld_image_infos:
 
 m_dyld_image_infos.erase(pos);
+found = true;
 break;
   }
 }
 
-if (pos == end) {
+if (!found) {
   if (log) {
 LLDB_LOGF(log, "Could not find image_info entry for unloading image:");
 image_infos[idx].PutToLog(log);



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] b9aedd9 - [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 2

2022-07-25 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-25T16:40:57-07:00
New Revision: b9aedd94e6796e4b4866ab4c091b736b3db58cb7

URL: 
https://github.com/llvm/llvm-project/commit/b9aedd94e6796e4b4866ab4c091b736b3db58cb7
DIFF: 
https://github.com/llvm/llvm-project/commit/b9aedd94e6796e4b4866ab4c091b736b3db58cb7.diff

LOG: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. 
Part 2

Improve LLDB reliability by fixing the following "uninitialized variables" 
static code inspection warnings from
scan.coverity.com:

1476275, 1274012, 1455035, 1364789, 1454282
1467483, 1406152, 1406255, 1454837, 1454416
1467446, 1462022, 1461909, 1420566, 1327228
1367767, 1431254, 1467299, 1312678, 1431780
1454731, 1490403

Differential Revision: https://reviews.llvm.org/D130528

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
lldb/source/Symbol/Type.cpp
lldb/source/Target/Process.cpp
lldb/source/Target/RegisterContextUnwind.cpp
lldb/source/Target/ThreadPlanCallFunction.cpp
lldb/source/Target/ThreadPlanTracer.cpp
lldb/source/Target/TraceDumper.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index acb131b8a775a..c396cb061c017 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -348,7 +348,7 @@ llvm::support::ulittle64_t 
read_register_u64(RegisterContext *reg_ctx,
 
 lldb_private::minidump::MinidumpContext_x86_64
 GetThreadContext_64(RegisterContext *reg_ctx) {
-  lldb_private::minidump::MinidumpContext_x86_64 thread_context;
+  lldb_private::minidump::MinidumpContext_x86_64 thread_context = {};
   thread_context.p1_home = {};
   thread_context.context_flags = static_cast(
   lldb_private::minidump::MinidumpContext_x86_64_Flags::x86_64_Flag |
@@ -534,7 +534,7 @@ Status MinidumpFileBuilder::AddException(const 
lldb::ProcessSP &process_sp) {
   helper_data.AppendData(
   &thread_context, sizeof(lldb_private::minidump::MinidumpContext_x86_64));
 
-  Exception exp_record;
+  Exception exp_record = {};
   exp_record.ExceptionCode =
   static_cast(stop_info_sp->GetValue());
   exp_record.ExceptionFlags = static_cast(0);

diff  --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp 
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 90118f9386da3..f7f52deb173fb 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -234,7 +234,7 @@ NativeProcessLinux::Factory::Launch(ProcessLaunchInfo 
&launch_info,
   }
 
   // Wait for the child process to trap on its call to execve.
-  int wstatus;
+  int wstatus = 0;
   ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
   assert(wpid == pid);
   (void)wpid;

diff  --git 
a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
index 11b300bc44fbb..691e7db3fc79e 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
@@ -95,7 +95,7 @@ static size_t k_num_register_infos =
 
 RegisterContextDarwin_arm64::RegisterContextDarwin_arm64(
 Thread &thread, uint32_t concrete_frame_idx)
-: RegisterContext(thread, concrete_frame_idx), gpr(), fpu(), exc() {
+: RegisterContext(thread, concrete_frame_idx), gpr(), fpu(), exc(), dbg() {
   uint32_t i;
   for (i = 0; i < kNumErrors; i++) {
 gpr_errs[i] = -1;

diff  --git a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp 
b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
index 7469e7633e71d..89ecc757a68f5 100644
--- a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
+++ b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
@@ -23,7 +23,8 @@ using namespace lldb_private;
 ThreadMemory::ThreadMemory(Process &process, tid_t tid,
const ValueObjectSP &thread_info_valobj_sp)
 : Thread(process, tid), m_backing_thread_sp(),
-  m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue() {}
+  m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue(),
+  m_register_data_addr(LLDB_INVALID_ADDRESS) {}
 

[Lldb-commits] [lldb] 9877159 - Revert "[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 2"

2022-07-25 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-25T18:23:19-07:00
New Revision: 9877159dd65ae6d2c4afc4c459d2eefe2473e616

URL: 
https://github.com/llvm/llvm-project/commit/9877159dd65ae6d2c4afc4c459d2eefe2473e616
DIFF: 
https://github.com/llvm/llvm-project/commit/9877159dd65ae6d2c4afc4c459d2eefe2473e616.diff

LOG: Revert "[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity 
scan. Part 2"

This reverts commit b9aedd94e6796e4b4866ab4c091b736b3db58cb7.

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
lldb/source/Symbol/Type.cpp
lldb/source/Target/Process.cpp
lldb/source/Target/RegisterContextUnwind.cpp
lldb/source/Target/ThreadPlanCallFunction.cpp
lldb/source/Target/ThreadPlanTracer.cpp
lldb/source/Target/TraceDumper.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index c396cb061c017..acb131b8a775a 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -348,7 +348,7 @@ llvm::support::ulittle64_t 
read_register_u64(RegisterContext *reg_ctx,
 
 lldb_private::minidump::MinidumpContext_x86_64
 GetThreadContext_64(RegisterContext *reg_ctx) {
-  lldb_private::minidump::MinidumpContext_x86_64 thread_context = {};
+  lldb_private::minidump::MinidumpContext_x86_64 thread_context;
   thread_context.p1_home = {};
   thread_context.context_flags = static_cast(
   lldb_private::minidump::MinidumpContext_x86_64_Flags::x86_64_Flag |
@@ -534,7 +534,7 @@ Status MinidumpFileBuilder::AddException(const 
lldb::ProcessSP &process_sp) {
   helper_data.AppendData(
   &thread_context, sizeof(lldb_private::minidump::MinidumpContext_x86_64));
 
-  Exception exp_record = {};
+  Exception exp_record;
   exp_record.ExceptionCode =
   static_cast(stop_info_sp->GetValue());
   exp_record.ExceptionFlags = static_cast(0);

diff  --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp 
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index f7f52deb173fb..90118f9386da3 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -234,7 +234,7 @@ NativeProcessLinux::Factory::Launch(ProcessLaunchInfo 
&launch_info,
   }
 
   // Wait for the child process to trap on its call to execve.
-  int wstatus = 0;
+  int wstatus;
   ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
   assert(wpid == pid);
   (void)wpid;

diff  --git 
a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
index 691e7db3fc79e..11b300bc44fbb 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
@@ -95,7 +95,7 @@ static size_t k_num_register_infos =
 
 RegisterContextDarwin_arm64::RegisterContextDarwin_arm64(
 Thread &thread, uint32_t concrete_frame_idx)
-: RegisterContext(thread, concrete_frame_idx), gpr(), fpu(), exc(), dbg() {
+: RegisterContext(thread, concrete_frame_idx), gpr(), fpu(), exc() {
   uint32_t i;
   for (i = 0; i < kNumErrors; i++) {
 gpr_errs[i] = -1;

diff  --git a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp 
b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
index 89ecc757a68f5..7469e7633e71d 100644
--- a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
+++ b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
@@ -23,8 +23,7 @@ using namespace lldb_private;
 ThreadMemory::ThreadMemory(Process &process, tid_t tid,
const ValueObjectSP &thread_info_valobj_sp)
 : Thread(process, tid), m_backing_thread_sp(),
-  m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue(),
-  m_register_data_addr(LLDB_INVALID_ADDRESS) {}
+  m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue() {}
 
 ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid,
llvm::StringRef name, llvm::StringRef queue,

diff  --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 24c942f1d290a..58b4fe3add1b3 100644
---

[Lldb-commits] [lldb] 4871dfc - [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 2

2022-07-25 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-25T20:52:45-07:00
New Revision: 4871dfc64e35e9cf07008c56299125694c81720a

URL: 
https://github.com/llvm/llvm-project/commit/4871dfc64e35e9cf07008c56299125694c81720a
DIFF: 
https://github.com/llvm/llvm-project/commit/4871dfc64e35e9cf07008c56299125694c81720a.diff

LOG: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. 
Part 2

Improve LLDB reliability by fixing the following "uninitialized variables" 
static code inspection warnings from
scan.coverity.com:

1476275, 1274012, 1455035, 1364789, 1454282
1467483, 1406152, 1406255, 1454837, 1454416
1467446, 1462022, 1461909, 1420566, 1327228
1367767, 1431254, 1467299, 1312678, 1431780
1454731, 1490403

Differential Revision: https://reviews.llvm.org/D130528

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
lldb/source/Symbol/Type.cpp
lldb/source/Target/Process.cpp
lldb/source/Target/RegisterContextUnwind.cpp
lldb/source/Target/ThreadPlanCallFunction.cpp
lldb/source/Target/ThreadPlanTracer.cpp
lldb/source/Target/TraceDumper.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index acb131b8a775a..c396cb061c017 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -348,7 +348,7 @@ llvm::support::ulittle64_t 
read_register_u64(RegisterContext *reg_ctx,
 
 lldb_private::minidump::MinidumpContext_x86_64
 GetThreadContext_64(RegisterContext *reg_ctx) {
-  lldb_private::minidump::MinidumpContext_x86_64 thread_context;
+  lldb_private::minidump::MinidumpContext_x86_64 thread_context = {};
   thread_context.p1_home = {};
   thread_context.context_flags = static_cast(
   lldb_private::minidump::MinidumpContext_x86_64_Flags::x86_64_Flag |
@@ -534,7 +534,7 @@ Status MinidumpFileBuilder::AddException(const 
lldb::ProcessSP &process_sp) {
   helper_data.AppendData(
   &thread_context, sizeof(lldb_private::minidump::MinidumpContext_x86_64));
 
-  Exception exp_record;
+  Exception exp_record = {};
   exp_record.ExceptionCode =
   static_cast(stop_info_sp->GetValue());
   exp_record.ExceptionFlags = static_cast(0);

diff  --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp 
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 90118f9386da3..f7f52deb173fb 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -234,7 +234,7 @@ NativeProcessLinux::Factory::Launch(ProcessLaunchInfo 
&launch_info,
   }
 
   // Wait for the child process to trap on its call to execve.
-  int wstatus;
+  int wstatus = 0;
   ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
   assert(wpid == pid);
   (void)wpid;

diff  --git 
a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
index 11b300bc44fbb..691e7db3fc79e 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
@@ -95,7 +95,7 @@ static size_t k_num_register_infos =
 
 RegisterContextDarwin_arm64::RegisterContextDarwin_arm64(
 Thread &thread, uint32_t concrete_frame_idx)
-: RegisterContext(thread, concrete_frame_idx), gpr(), fpu(), exc() {
+: RegisterContext(thread, concrete_frame_idx), gpr(), fpu(), exc(), dbg() {
   uint32_t i;
   for (i = 0; i < kNumErrors; i++) {
 gpr_errs[i] = -1;

diff  --git a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp 
b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
index 7469e7633e71d..89ecc757a68f5 100644
--- a/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
+++ b/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
@@ -23,7 +23,8 @@ using namespace lldb_private;
 ThreadMemory::ThreadMemory(Process &process, tid_t tid,
const ValueObjectSP &thread_info_valobj_sp)
 : Thread(process, tid), m_backing_thread_sp(),
-  m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue() {}
+  m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue(),
+  m_register_data_addr(LLDB_INVALID_ADDRESS) {}
 

[Lldb-commits] [lldb] e80dbfd - [LLDB][Reliability] Fix register value unpacking

2022-07-26 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-26T00:22:40-07:00
New Revision: e80dbfddc5aa567aea0a974708af4122c2b49829

URL: 
https://github.com/llvm/llvm-project/commit/e80dbfddc5aa567aea0a974708af4122c2b49829
DIFF: 
https://github.com/llvm/llvm-project/commit/e80dbfddc5aa567aea0a974708af4122c2b49829.diff

LOG: [LLDB][Reliability] Fix register value unpacking

Fix incorrect direction for bit-shifting.

Coverity warning 1355603 (scan.coverity.com)

Differential Revision: https://reviews.llvm.org/D130307

Added: 


Modified: 
lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp 
b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
index 569482c7b23b1..32430cd96d15a 100644
--- a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
+++ b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
@@ -97,7 +97,7 @@ uint64_t EmulationStateARM::ReadPseudoRegisterValue(uint32_t 
reg_num,
 uint32_t idx = reg_num - dwarf_d0;
 if (idx < 16)
   value = (uint64_t)m_vfp_regs.s_regs[idx * 2] |
-  ((uint64_t)m_vfp_regs.s_regs[idx * 2 + 1] >> 32);
+  ((uint64_t)m_vfp_regs.s_regs[idx * 2 + 1] << 32);
 else
   value = m_vfp_regs.d_regs[idx - 16];
   } else



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 2430156 - [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 3

2022-07-27 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-27T10:39:49-07:00
New Revision: 24301569f080d60f644d7a69496596cbd65079ce

URL: 
https://github.com/llvm/llvm-project/commit/24301569f080d60f644d7a69496596cbd65079ce
DIFF: 
https://github.com/llvm/llvm-project/commit/24301569f080d60f644d7a69496596cbd65079ce.diff

LOG: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. 
Part 3

Improve LLDB reliability by fixing the following "uninitialized variables" 
static code inspection warnings from
scan.coverity.com/projects/llvm:

1355854, 1347549, 1316348, 1372028, 1431625,
1315634, 1315637, 1355855, 1364803, 1420505,
1420563, 1420685, 1366014, 1203966, 1204029,
1204031, 1204032, 1328411, 1325969, 1325968,
1374921, 1094809

Differential Revision: https://reviews.llvm.org/D130602

Added: 


Modified: 
lldb/include/lldb/Core/LoadedModuleInfoList.h
lldb/include/lldb/DataFormatters/TypeSummary.h
lldb/include/lldb/Symbol/DebugMacros.h
lldb/include/lldb/Target/ProcessStructReader.h
lldb/include/lldb/Utility/Args.h
lldb/include/lldb/Utility/RegisterValue.h
lldb/include/lldb/Utility/StringExtractorGDBRemote.h
lldb/source/Breakpoint/BreakpointOptions.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Core/IOHandlerCursesGUI.cpp
lldb/source/Expression/FunctionCaller.cpp
lldb/source/Expression/LLVMUserExpression.cpp
lldb/source/Host/common/MainLoop.cpp
lldb/source/Interpreter/OptionGroupFormat.cpp
lldb/source/Interpreter/OptionGroupVariable.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/LoadedModuleInfoList.h 
b/lldb/include/lldb/Core/LoadedModuleInfoList.h
index 6ff4565458407..537a2b0f1d379 100644
--- a/lldb/include/lldb/Core/LoadedModuleInfoList.h
+++ b/lldb/include/lldb/Core/LoadedModuleInfoList.h
@@ -95,10 +95,10 @@ class LoadedModuleInfoList {
   protected:
 bool m_has[e_num];
 std::string m_name;
-lldb::addr_t m_link_map;
-lldb::addr_t m_base;
-bool m_base_is_offset;
-lldb::addr_t m_dynamic;
+lldb::addr_t m_link_map = LLDB_INVALID_ADDRESS;
+lldb::addr_t m_base = LLDB_INVALID_ADDRESS;
+bool m_base_is_offset = false;
+lldb::addr_t m_dynamic = LLDB_INVALID_ADDRESS;
   };
 
   LoadedModuleInfoList() = default;

diff  --git a/lldb/include/lldb/DataFormatters/TypeSummary.h 
b/lldb/include/lldb/DataFormatters/TypeSummary.h
index 30bc8cbf3feb3..a82641021dad3 100644
--- a/lldb/include/lldb/DataFormatters/TypeSummary.h
+++ b/lldb/include/lldb/DataFormatters/TypeSummary.h
@@ -263,7 +263,7 @@ class TypeSummaryImpl {
   typedef std::shared_ptr SharedPointer;
 
 protected:
-  uint32_t m_my_revision;
+  uint32_t m_my_revision = 0;
   Flags m_flags;
 
   TypeSummaryImpl(Kind kind, const TypeSummaryImpl::Flags &flags);

diff  --git a/lldb/include/lldb/Symbol/DebugMacros.h 
b/lldb/include/lldb/Symbol/DebugMacros.h
index 0ea70f5deb84a..fbc5be0ee6013 100644
--- a/lldb/include/lldb/Symbol/DebugMacros.h
+++ b/lldb/include/lldb/Symbol/DebugMacros.h
@@ -39,7 +39,7 @@ class DebugMacroEntry {
   static DebugMacroEntry
   CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp);
 
-  DebugMacroEntry() : m_type(INVALID) {}
+  DebugMacroEntry() : m_type(INVALID), m_line(0), m_debug_line_file_idx(0) {}
 
   ~DebugMacroEntry() = default;
 

diff  --git a/lldb/include/lldb/Target/ProcessStructReader.h 
b/lldb/include/lldb/Target/ProcessStructReader.h
index 8046ef4958bbe..4af51cac32890 100644
--- a/lldb/include/lldb/Target/ProcessStructReader.h
+++ b/lldb/include/lldb/Target/ProcessStructReader.h
@@ -39,7 +39,8 @@ class ProcessStructReader {
 
 public:
   ProcessStructReader(Process *process, lldb::addr_t base_addr,
-  CompilerType struct_type) {
+  CompilerType struct_type)
+  : m_byte_order(lldb::eByteOrderInvalid), m_addr_byte_size(0) {
 if (!process)
   return;
 if (base_addr == 0 || base_addr == LLDB_INVALID_ADDRESS)

diff  --git a/lldb/include/lldb/Utility/Args.h 
b/lldb/include/lldb/Utility/Args.h
index cecf6b1502b5b..7c20288aac72d 100644
--- a/lldb/include/lldb/Utility/Args.h
+++ b/lldb/include/lldb/Utility/Args.h
@@ -39,7 +39,7 @@ class Args {
 friend struct llvm::yaml::MappingTraits;
 
 std::unique_ptr ptr;
-char quote;
+char quote = '\0';
 
 char *data() { return ptr.get(); }
 
@@ -395,7 +395,7 @@ template <> struct 
MappingTraits {
   return lldb_private::Args::ArgEntry(value, quote);
 }
 StringRef value;
-uint8_t quote;
+uint8_t quote = '\0';
   };
   static void mapping(IO &io, lldb_private::Args::ArgEntry &v);
 };

diff  --git a/lldb/include/lldb/Utility/RegisterValue.h 
b/lldb/include/lldb/Utility/RegisterValue.h
index 1ece4f0eb79f7..a0bd493d80941 100644
--- a/lldb/include/lldb/Utility/RegisterValue.h
+++ b/lldb/include/lldb/Utility/RegisterValue.h
@@ -263,8 +263,8 @@ class RegisterValue {
 mutable uint8_t
 bytes[kMaxRegisterByteSize

[Lldb-commits] [lldb] 2cfcbe2 - [LLDB][NFC] Fix possible resource leak

2022-07-27 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-27T13:19:13-07:00
New Revision: 2cfcbe295a313846222ac9b35b14a261e77a89a8

URL: 
https://github.com/llvm/llvm-project/commit/2cfcbe295a313846222ac9b35b14a261e77a89a8
DIFF: 
https://github.com/llvm/llvm-project/commit/2cfcbe295a313846222ac9b35b14a261e77a89a8.diff

LOG: [LLDB][NFC] Fix possible resource leak

SymbolVendorPECOFF object is leaked on early return at line 110

Differential Revision: https://reviews.llvm.org/D130655

Added: 


Modified: 
lldb/source/Plugins/SymbolVendor/PECOFF/SymbolVendorPECOFF.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolVendor/PECOFF/SymbolVendorPECOFF.cpp 
b/lldb/source/Plugins/SymbolVendor/PECOFF/SymbolVendorPECOFF.cpp
index 9b651243152c9..0f8d3108998da 100644
--- a/lldb/source/Plugins/SymbolVendor/PECOFF/SymbolVendorPECOFF.cpp
+++ b/lldb/source/Plugins/SymbolVendor/PECOFF/SymbolVendorPECOFF.cpp
@@ -102,8 +102,6 @@ SymbolVendorPECOFF::CreateInstance(const lldb::ModuleSP 
&module_sp,
   // This objfile is for debugging purposes.
   dsym_objfile_sp->SetType(ObjectFile::eTypeDebugInfo);
 
-  SymbolVendorPECOFF *symbol_vendor = new SymbolVendorPECOFF(module_sp);
-
   // Get the module unified section list and add our debug sections to
   // that.
   SectionList *module_section_list = module_sp->GetSectionList();
@@ -132,6 +130,7 @@ SymbolVendorPECOFF::CreateInstance(const lldb::ModuleSP 
&module_sp,
 }
   }
 
+  SymbolVendorPECOFF *symbol_vendor = new SymbolVendorPECOFF(module_sp);
   symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp);
   return symbol_vendor;
 }



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 2e6b652 - [LLDB] Fix missing return value in SBBreakpointLocation::GetQueueName()

2022-07-28 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-28T16:08:35-07:00
New Revision: 2e6b6522296e40304ccd2766ad3233af8a0851bb

URL: 
https://github.com/llvm/llvm-project/commit/2e6b6522296e40304ccd2766ad3233af8a0851bb
DIFF: 
https://github.com/llvm/llvm-project/commit/2e6b6522296e40304ccd2766ad3233af8a0851bb.diff

LOG: [LLDB] Fix missing return value in SBBreakpointLocation::GetQueueName()

- Fix a typo in the function that never returns a significant value

- Add unit tests for the getters/setters in SBBreakpointLocation

- Verified the newly added unit test succeeds after the fix:
llvm-lit -sv  
lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py

Differential Revision: https://reviews.llvm.org/D130660

Added: 


Modified: 
lldb/source/API/SBBreakpointLocation.cpp

lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py

Removed: 




diff  --git a/lldb/source/API/SBBreakpointLocation.cpp 
b/lldb/source/API/SBBreakpointLocation.cpp
index 9143174377236..6c03aba15447f 100644
--- a/lldb/source/API/SBBreakpointLocation.cpp
+++ b/lldb/source/API/SBBreakpointLocation.cpp
@@ -374,7 +374,7 @@ const char *SBBreakpointLocation::GetQueueName() const {
   if (loc_sp) {
 std::lock_guard guard(
 loc_sp->GetTarget().GetAPIMutex());
-loc_sp->GetQueueName();
+return loc_sp->GetQueueName();
   }
   return nullptr;
 }

diff  --git 
a/lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
 
b/lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
index 85c55a44d7226..982e56a74e260 100644
--- 
a/lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
+++ 
b/lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
@@ -89,6 +89,53 @@ def shadowed_bkpt_cond_test(self):
 bkpt.SetCondition(bkpt_new_cond)
 self.assertEqual(bkpt.location[0].GetCondition(), bkpt_new_cond, 
"Didn't go back to tracking condition")
 
+# Test that set/get accessor methods on BreakpointLocation behave 
correctly.
+bkpt_loc = bkpt.GetLocationAtIndex(0)
+
+value = "MyQueue"
+bkpt_loc.SetQueueName(value)
+self.assertEqual(bkpt_loc.GetQueueName(), value,"Successfully set/get 
bp location QueueName")
+
+value = 5
+bkpt_loc.SetThreadID(value)
+self.assertEqual(bkpt_loc.GetThreadID(), value,"Successfully set/get 
bp location ThreadID")
+
+value = "1 == 0"
+bkpt_loc.SetCondition(value)
+self.assertEqual(bkpt_loc.GetCondition(), value,"Successfully set/get 
bp location Condition")
+
+value = 6
+bkpt_loc.SetThreadIndex(value)
+self.assertEqual(bkpt_loc.GetThreadIndex(), value,"Successfully 
set/get bp location ThreadIndex")
+
+value = "MyThread"
+bkpt_loc.SetThreadName(value)
+self.assertEqual(bkpt_loc.GetThreadName(), value,"Successfully set/get 
bp location ThreadName")
+
+value = 5
+bkpt_loc.SetIgnoreCount(value)
+self.assertEqual(bkpt_loc.GetIgnoreCount(), value,"Successfully 
set/get bp location IgnoreCount")
+
+for value in [True,False]:
+bkpt_loc.SetAutoContinue(value)
+self.assertEqual(bkpt_loc.GetAutoContinue(), value,"Successfully 
set/get bp location AutoContinue")
+
+for value in [True,False]:
+bkpt_loc.SetEnabled(value)
+self.assertEqual(bkpt_loc.IsEnabled(), value,"Successfully set/get 
bp location SetEnabled")
+
+# test set/get CommandLineCommands
+set_cmds = lldb.SBStringList()
+set_cmds.AppendString("frame var")
+set_cmds.AppendString("bt")
+bkpt_loc.SetCommandLineCommands(set_cmds)
+
+get_cmds = lldb.SBStringList()
+bkpt_loc.GetCommandLineCommands(get_cmds)
+self.assertEqual(set_cmds.GetSize(), get_cmds.GetSize(), "Size of 
command line commands")
+for idx, _ in  enumerate(set_cmds):
+self.assertEqual(set_cmds.GetStringAtIndex(idx), 
get_cmds.GetStringAtIndex(idx), "Command %d"%(idx))
+
 def shadowed_bkpt_command_test(self):
 """Test that options set on the breakpoint and location behave 
correctly."""
 # Breakpoint option propagation from bkpt to loc used to be done the 
first time



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] f7c961c - [LLDB][NFC][Reliability] Fixes for int overflow and uninitialized state

2022-07-29 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-29T13:31:17-07:00
New Revision: f7c961cc6ba71c9d1fb845807e31b3a278d13c2f

URL: 
https://github.com/llvm/llvm-project/commit/f7c961cc6ba71c9d1fb845807e31b3a278d13c2f
DIFF: 
https://github.com/llvm/llvm-project/commit/f7c961cc6ba71c9d1fb845807e31b3a278d13c2f.diff

LOG: [LLDB][NFC][Reliability] Fixes for int overflow and uninitialized state

Fixing potential int overflow and uninitialized variables.
These were found by Coverity static code inspection.

Differential Revision: https://reviews.llvm.org/D130795

Added: 


Modified: 
lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp 
b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
index f86609f3c5c1c..80cee99ef0f8f 100644
--- a/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ b/lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -633,7 +633,7 @@ bool EmulateInstructionARM64::EmulateADDSUBImm(const 
uint32_t opcode) {
 imm = imm12;
 break;
   case 1:
-imm = imm12 << 12;
+imm = static_cast(imm12) << 12;
 break;
   default:
 return false; // UNDEFINED;

diff  --git 
a/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.cpp 
b/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.cpp
index 222e4a2690e4f..f5525e3e3cb3d 100644
--- a/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.cpp
+++ b/lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.cpp
@@ -18,7 +18,7 @@ using namespace lldb_private;
 static inline uint64_t GetStatusBit(uint32_t wp_index) {
   // DR6: ...
   // 3210 <- status bits for bp./wp. i; 1 if hit
-  return 1 << wp_index;
+  return 1ULL << wp_index;
 }
 
 // Returns mask/value for global enable bit of wp_index in DR7
@@ -27,14 +27,14 @@ static inline uint64_t GetEnableBit(uint32_t wp_index) {
   // 33221100 <- global/local enable for bp./wp.; 1 if enabled
   // we use global bits because NetBSD kernel does not preserve local
   // bits reliably; Linux seems fine with either
-  return 1 << (2 * wp_index + 1);
+  return 1ULL << (2 * wp_index + 1);
 }
 
 // Returns mask for both enable bits of wp_index in DR7
 static inline uint64_t GetBothEnableBitMask(uint32_t wp_index) {
   // DR7: ...GLGLGLGL
   // 33221100 <- global/local enable for bp./wp.; 1 if enabled
-  return 3 << (2 * wp_index + 1);
+  return 3ULL << (2 * wp_index + 1);
 }
 
 // Returns value for type bits of wp_index in DR7
@@ -47,7 +47,7 @@ static inline uint64_t GetWatchTypeBits(uint32_t watch_flags,
   // wp.: ...
   //
   // where T - type is 01 for write, 11 for r/w
-  return watch_flags << (16 + 4 * wp_index);
+  return static_cast(watch_flags) << (16 + 4 * wp_index);
 }
 
 // Returns value for size bits of wp_index in DR7
@@ -63,7 +63,8 @@ static inline uint64_t GetWatchSizeBits(uint32_t size, 
uint32_t wp_index) {
   // 01 for 2 bytes
   // 10 for 8 bytes
   // 11 for 4 bytes
-  return (size == 8 ? 0x2 : size - 1) << (18 + 4 * wp_index);
+  return static_cast(size == 8 ? 0x2 : size - 1)
+ << (18 + 4 * wp_index);
 }
 
 // Returns bitmask for all bits controlling wp_index in DR7

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 6de5ab44f26f7..b6407af18cfdf 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2731,7 +2731,7 @@ void DWARFASTParserClang::ParseSingleMember(
 
   uint64_t field_bit_offset = (attrs.member_byte_offset == UINT32_MAX
? 0
-   : (attrs.member_byte_offset * 8));
+   : (attrs.member_byte_offset * 8ULL));
 
   if (attrs.bit_size > 0) {
 FieldInfo this_field_info;

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
index 7b4a5d8eca3ed..dacf2f4110a4f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -582,7 +582,7 @@ void DWARFUnit::SetStrOffsetsBase(dw_offset_t 
str_offsets_base) {
 dw_addr_t DWARFUnit::ReadAddressFromDebugAddrSection(uint32_t index) const {
   uint32_t index_size = GetAddressByteSize();
   dw_offset_t addr_base = GetAddrBase();
-  dw_addr_t offset = addr_base + index *

[Lldb-commits] [lldb] 30b3911 - [LLDB][NFC][Correctness] Fix bad null check

2022-08-01 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-01T14:45:26-07:00
New Revision: 30b39111973798451397a1360dc7abc3e2490c84

URL: 
https://github.com/llvm/llvm-project/commit/30b39111973798451397a1360dc7abc3e2490c84
DIFF: 
https://github.com/llvm/llvm-project/commit/30b39111973798451397a1360dc7abc3e2490c84.diff

LOG: [LLDB][NFC][Correctness] Fix bad null check

Fix incorrect null-check logic, likely cause by copy-paste

Differential Revision: https://reviews.llvm.org/D130937

Added: 


Modified: 
lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp 
b/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
index cbaa1fc7a2b12..fe64da873d22a 100644
--- a/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
+++ b/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
@@ -161,7 +161,7 @@ NativeProcessELF::GetLoadedSVR4Libraries() {
   GetAddressByteSize(), bytes_read);
   if (!status.Success())
 return status.ToError();
-  if (address == 0)
+  if (link_map == 0)
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Invalid link_map address");
 



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] d735307 - [LLDB][Reliability] Remove dead code.

2022-08-02 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-02T10:09:45-07:00
New Revision: d735307aa2be0ebcc37ddd8d4268635dcd1e9d4e

URL: 
https://github.com/llvm/llvm-project/commit/d735307aa2be0ebcc37ddd8d4268635dcd1e9d4e
DIFF: 
https://github.com/llvm/llvm-project/commit/d735307aa2be0ebcc37ddd8d4268635dcd1e9d4e.diff

LOG: [LLDB][Reliability] Remove dead code.

Remove redundant code that can never execute due to preceeding logic checks in 
the code.

Differential Revision: https://reviews.llvm.org/D130929

Added: 


Modified: 
lldb/source/API/SBFrame.cpp
lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
lldb/source/Target/Platform.cpp

Removed: 




diff  --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index ea9c2bb747e1e..4157c20cbabb5 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -739,7 +739,7 @@ SBValueList SBFrame::GetVariables(bool arguments, bool 
locals, bool statics,
 lldb::DynamicValueType use_dynamic =
 frame->CalculateTarget()->GetPreferDynamicValue();
 const bool include_runtime_support_values =
-target ? target->GetDisplayRuntimeSupportValues() : false;
+target->GetDisplayRuntimeSupportValues();
 
 SBVariablesOptions options;
 options.SetIncludeArguments(arguments);

diff  --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp 
b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
index 9dfc50564e64f..7b948d8fa8cb2 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
@@ -612,9 +612,6 @@ static bool LoadValueFromConsecutiveGPRRegisters(
   ++NGRN;
 }
 
-if (reg_info == nullptr)
-  return false;
-
 const lldb::addr_t value_addr =
 reg_ctx->ReadRegisterAsUnsigned(reg_info, LLDB_INVALID_ADDRESS);
 

diff  --git a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp 
b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
index 2896f5920db90..a0b2d077a22f2 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
@@ -582,9 +582,6 @@ static bool LoadValueFromConsecutiveGPRRegisters(
   ++NGRN;
 }
 
-if (reg_info == nullptr)
-  return false;
-
 const lldb::addr_t value_addr =
 reg_ctx->ReadRegisterAsUnsigned(reg_info, LLDB_INVALID_ADDRESS);
 

diff  --git a/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp 
b/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
index a862da551813d..4b7fad08f00c2 100644
--- a/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
+++ b/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
@@ -65,9 +65,6 @@ bool lldb_private::formatters::CMTimeSummaryProvider(
 return true;
   }
 
-  if (timescale == 0)
-return false;
-
   switch (timescale) {
   case 0:
 return false;

diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index b9b32bff07309..717dc968f37db 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1772,25 +1772,21 @@ lldb::ProcessSP 
Platform::DoConnectProcess(llvm::StringRef connect_url,
   error.Clear();
 
   if (!target) {
-ArchSpec arch;
-if (target && target->GetArchitecture().IsValid())
-  arch = target->GetArchitecture();
-else
-  arch = Target::GetDefaultArchitecture();
+ArchSpec arch = Target::GetDefaultArchitecture();
 
-const char *triple = "";
-if (arch.IsValid())
-  triple = arch.GetTriple().getTriple().c_str();
+const char *triple =
+arch.IsValid() ? arch.GetTriple().getTriple().c_str() : "";
 
 TargetSP new_target_sp;
 error = debugger.GetTargetList().CreateTarget(
 debugger, "", triple, eLoadDependentsNo, nullptr, new_target_sp);
+
 target = new_target_sp.get();
+if (!target || error.Fail()) {
+  return nullptr;
+}
   }
 
-  if (!target || error.Fail())
-return nullptr;
-
   lldb::ProcessSP process_sp =
   target->CreateProcess(debugger.GetListener(), plugin_name, nullptr, 
true);
 



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 0a56927 - [LLDB][NFC] Fix LLDB_WATCH_TYPE_IS_VALID macro

2022-08-02 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-02T13:05:29-07:00
New Revision: 0a569274cb3b10401593ebd6eef01b74abbf4504

URL: 
https://github.com/llvm/llvm-project/commit/0a569274cb3b10401593ebd6eef01b74abbf4504
DIFF: 
https://github.com/llvm/llvm-project/commit/0a569274cb3b10401593ebd6eef01b74abbf4504.diff

LOG: [LLDB][NFC] Fix LLDB_WATCH_TYPE_IS_VALID macro

LLDB_WATCH_TYPE_IS_VALID would always return true when validating watchpoint 
type
by using bitwise-or instead of bitwise-and to apply validation flags.

Differential Revision: https://reviews.llvm.org/D130972

Added: 


Modified: 
lldb/include/lldb/lldb-defines.h

Removed: 




diff  --git a/lldb/include/lldb/lldb-defines.h 
b/lldb/include/lldb/lldb-defines.h
index 339071bbfc31..ad1283bfd229 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -45,7 +45,7 @@
 #define LLDB_WATCH_TYPE_READ (1u << 0)
 #define LLDB_WATCH_TYPE_WRITE (1u << 1)
 #define LLDB_WATCH_TYPE_IS_VALID(type) 
\
-  ((type | LLDB_WATCH_TYPE_READ) || (type | LLDB_WATCH_TYPE_WRITE))
+  ((type & LLDB_WATCH_TYPE_READ) || (type & LLDB_WATCH_TYPE_WRITE))
 
 // Generic Register Numbers
 #define LLDB_REGNUM_GENERIC_PC 0// Program Counter



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 4502e35 - [LLDB][NFC] Fix incorrect return status Some functions always return 'false' for both success and fail return paths.

2022-08-02 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-02T15:56:23-07:00
New Revision: 4502e3531f623c47e71d3a159580a72560b90954

URL: 
https://github.com/llvm/llvm-project/commit/4502e3531f623c47e71d3a159580a72560b90954
DIFF: 
https://github.com/llvm/llvm-project/commit/4502e3531f623c47e71d3a159580a72560b90954.diff

LOG: [LLDB][NFC] Fix incorrect return status Some functions always return 
'false' for both success and fail return paths.

Differential Revision: https://reviews.llvm.org/D131013

Added: 


Modified: 
lldb/source/Plugins/Language/ObjC/NSArray.cpp
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
lldb/source/Plugins/Language/ObjC/NSSet.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Language/ObjC/NSArray.cpp 
b/lldb/source/Plugins/Language/ObjC/NSArray.cpp
index adda04e18629c..876efda9b988f 100644
--- a/lldb/source/Plugins/Language/ObjC/NSArray.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSArray.cpp
@@ -532,9 +532,8 @@ lldb_private::formatters::
 process_sp->ReadMemory(data_location, m_data_64, sizeof(D64),
error);
   }
-  if (error.Fail())
-return false;
-  return false;
+
+  return error.Success();
 }
 
 bool
@@ -675,9 +674,8 @@ 
lldb_private::formatters::GenericNSArrayISyntheticFrontEnd::
 process_sp->ReadMemory(data_location, m_data_64, sizeof(D64),
error);
   }
-  if (error.Fail())
-return false;
-  return false;
+
+  return error.Success();
 }
 
 template 

diff  --git a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp 
b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
index e5e62b534560a..be74338258283 100644
--- a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
@@ -1121,9 +1121,8 @@ 
lldb_private::formatters::GenericNSDictionaryMSyntheticFrontEnd::
 process_sp->ReadMemory(data_location, m_data_64, sizeof(D64),
error);
   }
-  if (error.Fail())
-return false;
-  return true;
+
+  return error.Success();
 }
 
 template 
@@ -1284,9 +1283,8 @@ lldb_private::formatters::Foundation1100::
 process_sp->ReadMemory(data_location, m_data_64, sizeof(DataDescriptor_64),
error);
   }
-  if (error.Fail())
-return false;
-  return false;
+
+  return error.Success();
 }
 
 bool

diff  --git a/lldb/source/Plugins/Language/ObjC/NSSet.cpp 
b/lldb/source/Plugins/Language/ObjC/NSSet.cpp
index b5c8e849abccb..fac8594d0c7d9 100644
--- a/lldb/source/Plugins/Language/ObjC/NSSet.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSSet.cpp
@@ -461,7 +461,7 @@ bool 
lldb_private::formatters::NSSetISyntheticFrontEnd::Update() {
   if (error.Fail())
 return false;
   m_data_ptr = data_location + m_ptr_size;
-  return false;
+  return true;
 }
 
 bool lldb_private::formatters::NSSetISyntheticFrontEnd::MightHaveChildren() {
@@ -735,9 +735,7 @@ lldb_private::formatters::
 process_sp->ReadMemory(data_location, m_data_64, sizeof(D64),
error);
   }
-  if (error.Fail())
-return false;
-  return false;
+  return error.Success();
 }
 
 template 



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 5a906b7 - [LLDB][NFC] Fix potential div by 0 "count" can be zero potentially causing div by 0

2022-08-03 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-03T16:08:18-07:00
New Revision: 5a906b70c11ecd60082ff080789a6700890322e1

URL: 
https://github.com/llvm/llvm-project/commit/5a906b70c11ecd60082ff080789a6700890322e1
DIFF: 
https://github.com/llvm/llvm-project/commit/5a906b70c11ecd60082ff080789a6700890322e1.diff

LOG: [LLDB][NFC] Fix potential div by 0 "count" can be zero potentially causing 
div by 0

Differential Revision: https://reviews.llvm.org/D130939

Added: 


Modified: 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 8687175ee36c4..c468ed970f912 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2441,6 +2441,8 @@ static void MakeSpeedTestPacket(StreamString &packet, 
uint32_t send_size,
 
 duration
 calculate_standard_deviation(const std::vector> &v) {
+  if (v.size() == 0)
+return duration::zero();
   using Dur = duration;
   Dur sum = std::accumulate(std::begin(v), std::end(v), Dur());
   Dur mean = sum / v.size();
@@ -2458,7 +2460,7 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const 
uint32_t num_packets,
uint32_t max_recv,
uint64_t recv_amount,
bool json, Stream &strm) {
-  uint32_t i;
+
   if (SendSpeedTestPacket(0, 0)) {
 StreamString packet;
 if (json)
@@ -2483,7 +2485,7 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const 
uint32_t num_packets,
 packet_times.clear();
 // Test how long it takes to send 'num_packets' packets
 const auto start_time = steady_clock::now();
-for (i = 0; i < num_packets; ++i) {
+for (uint32_t i = 0; i < num_packets; ++i) {
   const auto packet_start_time = steady_clock::now();
   StringExtractorGDBRemote response;
   SendPacketAndWaitForResponse(packet.GetString(), response);
@@ -2495,7 +2497,8 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const 
uint32_t num_packets,
 
 float packets_per_second =
 ((float)num_packets) / duration(total_time).count();
-auto average_per_packet = total_time / num_packets;
+auto average_per_packet = num_packets > 0 ? total_time / num_packets
+  : duration::zero();
 const duration standard_deviation =
 calculate_standard_deviation(packet_times);
 if (json) {
@@ -2551,7 +2554,9 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const 
uint32_t num_packets,
   (1024.0 * 1024.0);
 float packets_per_second =
 ((float)packet_count) / duration(total_time).count();
-const auto average_per_packet = total_time / packet_count;
+const auto average_per_packet = packet_count > 0
+? total_time / packet_count
+: duration::zero();
 
 if (json) {
   strm.Format("{0}\n {{\"send_size\" : {1,6}, \"recv_size\" : "



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] bcac7b3 - [LLDB] Missing break in a switch statement alters the execution flow.

2022-08-05 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-05T18:33:18-07:00
New Revision: bcac7b3acb1972bdfabe3c84f51243e9a353e7fe

URL: 
https://github.com/llvm/llvm-project/commit/bcac7b3acb1972bdfabe3c84f51243e9a353e7fe
DIFF: 
https://github.com/llvm/llvm-project/commit/bcac7b3acb1972bdfabe3c84f51243e9a353e7fe.diff

LOG:   [LLDB] Missing break in a switch statement alters the execution flow.

Looks like a typo from the past code changes.

Differential Revision: https://reviews.llvm.org/D131244

Added: 


Modified: 
lldb/source/Plugins/Process/Utility/ARMUtils.h

Removed: 




diff  --git a/lldb/source/Plugins/Process/Utility/ARMUtils.h 
b/lldb/source/Plugins/Process/Utility/ARMUtils.h
index bbe4c9a35fa6..a7aaa5ac7a1f 100644
--- a/lldb/source/Plugins/Process/Utility/ARMUtils.h
+++ b/lldb/source/Plugins/Process/Utility/ARMUtils.h
@@ -25,7 +25,8 @@ static inline uint32_t DecodeImmShift(const uint32_t type, 
const uint32_t imm5,
   ARM_ShifterType &shift_t) {
   switch (type) {
   default:
-  // assert(0 && "Invalid shift type");
+assert(0 && "Invalid shift type");
+break;
   case 0:
 shift_t = SRType_LSL;
 return imm5;
@@ -302,7 +303,7 @@ static inline uint32_t ARMExpandImm(uint32_t opcode) {
 // (imm32, carry_out) = ThumbExpandImm_C(imm12, carry_in)
 static inline uint32_t ThumbExpandImm_C(uint32_t opcode, uint32_t carry_in,
 uint32_t &carry_out) {
-  uint32_t imm32; // the expanded result
+  uint32_t imm32 = 0; // the expanded result
   const uint32_t i = bit(opcode, 26);
   const uint32_t imm3 = bits(opcode, 14, 12);
   const uint32_t abcdefgh = bits(opcode, 7, 0);
@@ -311,6 +312,8 @@ static inline uint32_t ThumbExpandImm_C(uint32_t opcode, 
uint32_t carry_in,
   if (bits(imm12, 11, 10) == 0) {
 switch (bits(imm12, 9, 8)) {
 default: // Keep static analyzer happy with a default case
+  break;
+
 case 0:
   imm32 = abcdefgh;
   break;



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] aa4977f - [LLDB][NFC] Reliability fixes to TCPSocket code

2022-08-06 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-06T23:06:55-07:00
New Revision: aa4977f2e1354bb5e1937235dd12199839ab0801

URL: 
https://github.com/llvm/llvm-project/commit/aa4977f2e1354bb5e1937235dd12199839ab0801
DIFF: 
https://github.com/llvm/llvm-project/commit/aa4977f2e1354bb5e1937235dd12199839ab0801.diff

LOG: [LLDB][NFC] Reliability fixes to TCPSocket code

Patch the following issues found by static code inspection:
- Unchecked return values from lib calls
- Passing potentially negative arg into a function that requires non-negative 
input
- Possible socket double-close

Differential Revision: https://reviews.llvm.org/D131294

Added: 


Modified: 
lldb/source/Host/common/TCPSocket.cpp

Removed: 




diff  --git a/lldb/source/Host/common/TCPSocket.cpp 
b/lldb/source/Host/common/TCPSocket.cpp
index eabc9fef8a661..f424b42db7b64 100644
--- a/lldb/source/Host/common/TCPSocket.cpp
+++ b/lldb/source/Host/common/TCPSocket.cpp
@@ -174,7 +174,10 @@ Status TCPSocket::Connect(llvm::StringRef name) {
   continue;
 }
 
-SetOptionNoDelay();
+if (-1 == SetOptionNoDelay()) {
+  Close();
+  continue;
+}
 
 error.Clear();
 return error;
@@ -200,15 +203,18 @@ Status TCPSocket::Listen(llvm::StringRef name, int 
backlog) {
   for (SocketAddress &address : addresses) {
 int fd = Socket::CreateSocket(address.GetFamily(), kType, IPPROTO_TCP,
   m_child_processes_inherit, error);
-if (error.Fail())
+if (error.Fail() || fd < 0)
   continue;
 
 // enable local address reuse
 int option_value = 1;
 set_socket_option_arg_type option_value_p =
 reinterpret_cast(&option_value);
-::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, option_value_p,
- sizeof(option_value));
+if (-1 == ::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, option_value_p,
+   sizeof(option_value))) {
+  CLOSE_SOCKET(fd);
+  continue;
+}
 
 SocketAddress listen_address = address;
 if(!listen_address.IsLocalhost())
@@ -255,8 +261,8 @@ Status TCPSocket::Accept(Socket *&conn_socket) {
 return error;
   }
 
-  int sock = -1;
-  int listen_sock = -1;
+  int sock = kInvalidSocketValue;
+  int listen_sock = kInvalidSocketValue;
   lldb_private::SocketAddress AcceptAddr;
   MainLoop accept_loop;
   std::vector handles;
@@ -288,7 +294,10 @@ Status TCPSocket::Accept(Socket *&conn_socket) {
 
 lldb_private::SocketAddress &AddrIn = m_listen_sockets[listen_sock];
 if (!AddrIn.IsAnyAddr() && AcceptAddr != AddrIn) {
-  CLOSE_SOCKET(sock);
+  if (kInvalidSocketValue != sock) {
+CLOSE_SOCKET(sock);
+sock = kInvalidSocketValue;
+  }
   llvm::errs() << llvm::formatv(
   "error: rejecting incoming connection from {0} (expecting {1})",
   AcceptAddr.GetIPAddress(), AddrIn.GetIPAddress());



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 06ff46d - [LLDB][NFC] Fix suspicious bitwise expression in PrintBTEntry()

2022-08-08 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-08T09:04:22-07:00
New Revision: 06ff46d2d77feba285e672e2da42039c88dc965a

URL: 
https://github.com/llvm/llvm-project/commit/06ff46d2d77feba285e672e2da42039c88dc965a
DIFF: 
https://github.com/llvm/llvm-project/commit/06ff46d2d77feba285e672e2da42039c88dc965a.diff

LOG: [LLDB][NFC] Fix suspicious bitwise expression in PrintBTEntry()

Current application of bitwise-OR to a binary mask always results in True, 
which seems
inconsistent with the intent of the statement, a likely typo.

Differential Revision: https://reviews.llvm.org/D131312

Added: 


Modified: 
lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp

Removed: 




diff  --git a/lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp 
b/lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
index b19d8b7387bb..de6d50038a27 100644
--- a/lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
+++ b/lldb/tools/intel-features/intel-mpx/cli-wrapper-mpxtable.cpp
@@ -63,7 +63,7 @@ static void PrintBTEntry(lldb::addr_t lbound, lldb::addr_t 
ubound,
   const lldb::addr_t one_cmpl64 = ~((lldb::addr_t)0);
   const lldb::addr_t one_cmpl32 = ~((uint32_t)0);
 
-  if ((lbound == one_cmpl64 || one_cmpl32) && ubound == 0) {
+  if ((lbound == one_cmpl64 || lbound == one_cmpl32) && ubound == 0) {
 result.Printf("Null bounds on map: pointer value = 0x%" PRIu64 "\n", 
value);
   } else {
 result.Printf("lbound = 0x%" PRIu64 ",", lbound);



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] db9322b - [LLDB][NFC] Reliability fixes for ObjectFileMachO.cpp

2022-08-10 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-10T15:16:37-07:00
New Revision: db9322b2066c55254e7691efeab863f43bfcc084

URL: 
https://github.com/llvm/llvm-project/commit/db9322b2066c55254e7691efeab863f43bfcc084
DIFF: 
https://github.com/llvm/llvm-project/commit/db9322b2066c55254e7691efeab863f43bfcc084.diff

LOG: [LLDB][NFC] Reliability fixes for ObjectFileMachO.cpp

Static code inspection guided fixes for the following issues:
- dead code
- buffer not null-terminated
- null-dereference
- out-of-bounds access

Differential Revision: https://reviews.llvm.org/D131554

Added: 


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 73597ae3fb183..e4832dad1e476 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -533,8 +533,13 @@ class RegisterContextDarwin_arm_Mach : public 
RegisterContextDarwin_arm {
   case GPRRegSet:
 // On ARM, the CPSR register is also included in the count but it is
 // not included in gpr.r so loop until (count-1).
-for (uint32_t i = 0; i < (count - 1); ++i) {
-  gpr.r[i] = data.GetU32(&offset);
+
+// Prevent static analysis warnings by explicitly contstraining 'count'
+// to acceptable range. Handle possible underflow of count-1
+if (count > 0 && count <= sizeof(gpr.r) / sizeof(gpr.r[0])) {
+  for (uint32_t i = 0; i < (count - 1); ++i) {
+gpr.r[i] = data.GetU32(&offset);
+  }
 }
 // Save cpsr explicitly.
 gpr.cpsr = data.GetU32(&offset);
@@ -544,7 +549,7 @@ class RegisterContextDarwin_arm_Mach : public 
RegisterContextDarwin_arm {
 break;
 
   case FPURegSet: {
-uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats.s[0];
+uint8_t *fpu_reg_buf = (uint8_t *)&fpu.floats;
 const int fpu_reg_buf_size = sizeof(fpu.floats);
 if (data.ExtractBytes(offset, fpu_reg_buf_size, eByteOrderLittle,
   fpu_reg_buf) == fpu_reg_buf_size) {
@@ -4116,8 +4121,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 sym[sym_idx].SetReExportedSymbolName(reexport_name);
 set_value = false;
 reexport_shlib_needs_fixup[sym_idx] = reexport_name;
-indirect_symbol_names.insert(
-ConstString(symbol_name + ((symbol_name[0] == '_') ? 1 : 0)));
+indirect_symbol_names.insert(ConstString(
+symbol_name +
+((symbol_name && (symbol_name[0] == '_')) ? 1 : 0)));
   } else
 type = eSymbolTypeUndefined;
 } break;
@@ -6335,6 +6341,11 @@ static offset_t CreateAllImageInfosPayload(
   continue;
 ConstString name = section->GetName();
 segment_vmaddr seg_vmaddr;
+// This is the uncommon case where strncpy is exactly
+// the right one, doesn't need to be nul terminated.
+// The segment name in a Mach-O LC_SEGMENT/LC_SEGMENT_64 is char[16] 
and
+// is not guaranteed to be nul-terminated if all 16 characters are
+// used.
 strncpy(seg_vmaddr.segname, name.AsCString(),
 sizeof(seg_vmaddr.segname));
 seg_vmaddr.vmaddr = vmaddr;
@@ -6726,8 +6737,10 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
   buffer.PutHex32(sizeof(llvm::MachO::note_command));
   char namebuf[16];
   memset(namebuf, 0, sizeof(namebuf));
-  // this is the uncommon case where strncpy is exactly
+  // This is the uncommon case where strncpy is exactly
   // the right one, doesn't need to be nul terminated.
+  // LC_NOTE name field is char[16] and is not guaranteed to be
+  // nul-terminated.
   strncpy(namebuf, lcnote->name.c_str(), sizeof(namebuf));
   buffer.PutRawBytes(namebuf, sizeof(namebuf));
   buffer.PutHex64(lcnote->payload_file_offset);
@@ -6885,8 +6898,10 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
 }
 uint32_t imgcount = m_data.GetU32(&offset);
 uint64_t entries_fileoff = m_data.GetU64(&offset);
-offset += 4; // uint32_t entries_size;
-offset += 4; // uint32_t unused;
+/* leaving the following dead code as comments for spec documentation
+offset += 4; // uint32_t entries_size;
+offset += 4; // uint32_t unused;
+*/
 
 offset = entries_fileoff;
 for (uint32_t i = 0; i < imgcount; i++) {



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] f4c21ab - [LLDB][NFC] Clean up dead code

2022-08-10 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-10T15:22:15-07:00
New Revision: f4c21ab8b32d57d6db643b5f230b8ceb7b06c84c

URL: 
https://github.com/llvm/llvm-project/commit/f4c21ab8b32d57d6db643b5f230b8ceb7b06c84c
DIFF: 
https://github.com/llvm/llvm-project/commit/f4c21ab8b32d57d6db643b5f230b8ceb7b06c84c.diff

LOG: [LLDB][NFC] Clean up dead code

Remove unreachable code that will never execute.

Differential Revision: https://reviews.llvm.org/D131613

Added: 


Modified: 
lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp 
b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
index b00a177366794..103551da2857c 100644
--- a/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ b/lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -3769,10 +3769,6 @@ bool EmulateInstructionARM::EmulateShiftImm(const 
uint32_t opcode,
 
 switch (use_encoding) {
 case eEncodingT1:
-  // Due to the above special case handling!
-  if (shift_type == SRType_ROR)
-return false;
-
   Rd = Bits32(opcode, 2, 0);
   Rm = Bits32(opcode, 5, 3);
   setflags = !InITBlock();
@@ -4139,8 +4135,6 @@ bool EmulateInstructionARM::EmulateLDMDA(const uint32_t 
opcode,
 
 // if wback && registers == '0' then R[n] = R[n] - 
4*BitCount(registers);
 if (wback && BitIsClear(registers, n)) {
-  if (!success)
-return false;
 
   offset = (addr_byte_size * BitCount(registers)) * -1;
   context.type = EmulateInstruction::eContextAdjustBaseRegister;
@@ -4277,8 +4271,6 @@ bool EmulateInstructionARM::EmulateLDMDB(const uint32_t 
opcode,
 
 // if wback && registers == '0' then R[n] = R[n] - 
4*BitCount(registers);
 if (wback && BitIsClear(registers, n)) {
-  if (!success)
-return false;
 
   offset = (addr_byte_size * BitCount(registers)) * -1;
   context.type = EmulateInstruction::eContextAdjustBaseRegister;
@@ -4391,8 +4383,6 @@ bool EmulateInstructionARM::EmulateLDMIB(const uint32_t 
opcode,
 
 // if wback && registers == '0' then R[n] = R[n] + 
4*BitCount(registers);
 if (wback && BitIsClear(registers, n)) {
-  if (!success)
-return false;
 
   offset = addr_byte_size * BitCount(registers);
   context.type = EmulateInstruction::eContextAdjustBaseRegister;



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] ab6a082 - [LLDB] Fix out-of-bounds memory access in EmulationStateArm

2022-08-11 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-11T01:34:18-07:00
New Revision: ab6a0823afc7e4cc660f0fd3bd07f791fe9e103f

URL: 
https://github.com/llvm/llvm-project/commit/ab6a0823afc7e4cc660f0fd3bd07f791fe9e103f
DIFF: 
https://github.com/llvm/llvm-project/commit/ab6a0823afc7e4cc660f0fd3bd07f791fe9e103f.diff

LOG: [LLDB] Fix out-of-bounds memory access in EmulationStateArm

Functionally broken code for reading and writing registers, likely due to typos,
and could cause out-of-bounds memory access.

Differential Revision: https://reviews.llvm.org/D131658

Added: 


Modified: 
lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp 
b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
index da679a3e85471..4bfff9277f08b 100644
--- a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
+++ b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
@@ -51,7 +51,7 @@ bool 
EmulationStateARM::LoadPseudoRegistersFromFrame(StackFrame &frame) {
 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
   uint64_t value = reg_value.GetAsUInt64();
   uint32_t idx = i - dwarf_d0;
-  if (i < 16) {
+  if (idx < 16) {
 m_vfp_regs.s_regs[idx * 2] = (uint32_t)value;
 m_vfp_regs.s_regs[idx * 2 + 1] = (uint32_t)(value >> 32);
   } else
@@ -92,7 +92,7 @@ uint64_t EmulationStateARM::ReadPseudoRegisterValue(uint32_t 
reg_num,
 value = m_gpr[reg_num - dwarf_r0];
   else if ((dwarf_s0 <= reg_num) && (reg_num <= dwarf_s31)) {
 uint32_t idx = reg_num - dwarf_s0;
-value = m_vfp_regs.d_regs[idx];
+value = m_vfp_regs.s_regs[idx];
   } else if ((dwarf_d0 <= reg_num) && (reg_num <= dwarf_d31)) {
 uint32_t idx = reg_num - dwarf_d0;
 if (idx < 16)



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 256ba77 - [LLDB][NFC] Fix the style issue in TCPSocket

2022-08-11 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-11T18:02:01-07:00
New Revision: 256ba7738ea8a07372a82cadd29e9c08fdf9145c

URL: 
https://github.com/llvm/llvm-project/commit/256ba7738ea8a07372a82cadd29e9c08fdf9145c
DIFF: 
https://github.com/llvm/llvm-project/commit/256ba7738ea8a07372a82cadd29e9c08fdf9145c.diff

LOG: [LLDB][NFC] Fix the style issue in TCPSocket

Style fixes for the entire file

Differential Revision: https://reviews.llvm.org/D131543

Added: 


Modified: 
lldb/source/Host/common/TCPSocket.cpp

Removed: 




diff  --git a/lldb/source/Host/common/TCPSocket.cpp 
b/lldb/source/Host/common/TCPSocket.cpp
index f424b42db7b64..91465d2fe4976 100644
--- a/lldb/source/Host/common/TCPSocket.cpp
+++ b/lldb/source/Host/common/TCPSocket.cpp
@@ -167,14 +167,14 @@ Status TCPSocket::Connect(llvm::StringRef name) {
 
 address.SetPort(host_port->port);
 
-if (-1 == llvm::sys::RetryAfterSignal(-1, ::connect, GetNativeSocket(),
-  &address.sockaddr(),
-  address.GetLength())) {
+if (llvm::sys::RetryAfterSignal(-1, ::connect, GetNativeSocket(),
+&address.sockaddr(),
+address.GetLength()) == -1) {
   Close();
   continue;
 }
 
-if (-1 == SetOptionNoDelay()) {
+if (SetOptionNoDelay() == -1) {
   Close();
   continue;
 }
@@ -210,8 +210,8 @@ Status TCPSocket::Listen(llvm::StringRef name, int backlog) 
{
 int option_value = 1;
 set_socket_option_arg_type option_value_p =
 reinterpret_cast(&option_value);
-if (-1 == ::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, option_value_p,
-   sizeof(option_value))) {
+if (::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, option_value_p,
+ sizeof(option_value)) == -1) {
   CLOSE_SOCKET(fd);
   continue;
 }
@@ -224,10 +224,10 @@ Status TCPSocket::Listen(llvm::StringRef name, int 
backlog) {
 
 int err =
 ::bind(fd, &listen_address.sockaddr(), listen_address.GetLength());
-if (-1 != err)
+if (err != -1)
   err = ::listen(fd, backlog);
 
-if (-1 == err) {
+if (err == -1) {
   error = GetLastSocketError();
   CLOSE_SOCKET(fd);
   continue;
@@ -294,7 +294,7 @@ Status TCPSocket::Accept(Socket *&conn_socket) {
 
 lldb_private::SocketAddress &AddrIn = m_listen_sockets[listen_sock];
 if (!AddrIn.IsAnyAddr() && AcceptAddr != AddrIn) {
-  if (kInvalidSocketValue != sock) {
+  if (sock != kInvalidSocketValue) {
 CLOSE_SOCKET(sock);
 sock = kInvalidSocketValue;
   }



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] b2cb417 - [LLDB][NFC] Reliability fixes for ObjectFileMachO.cpp (part 2)

2022-08-11 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-11T21:08:18-07:00
New Revision: b2cb417ed9a69528ddd9abac704ba12ef5b8f932

URL: 
https://github.com/llvm/llvm-project/commit/b2cb417ed9a69528ddd9abac704ba12ef5b8f932
DIFF: 
https://github.com/llvm/llvm-project/commit/b2cb417ed9a69528ddd9abac704ba12ef5b8f932.diff

LOG: [LLDB][NFC] Reliability fixes for ObjectFileMachO.cpp (part 2)

Add the fixes suggested post-push in D131554

Differential Revision: https://reviews.llvm.org/D131743

Added: 


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 e4832dad1e476..dbf3afff7b0da 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -4114,16 +4114,15 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 switch (n_type) {
 case N_INDR: {
   const char *reexport_name_cstr = strtab_data.PeekCStr(nlist.n_value);
-  if (reexport_name_cstr && reexport_name_cstr[0]) {
+  if (reexport_name_cstr && reexport_name_cstr[0] && symbol_name) {
 type = eSymbolTypeReExported;
 ConstString reexport_name(reexport_name_cstr +
   ((reexport_name_cstr[0] == '_') ? 1 : 
0));
 sym[sym_idx].SetReExportedSymbolName(reexport_name);
 set_value = false;
 reexport_shlib_needs_fixup[sym_idx] = reexport_name;
-indirect_symbol_names.insert(ConstString(
-symbol_name +
-((symbol_name && (symbol_name[0] == '_')) ? 1 : 0)));
+indirect_symbol_names.insert(
+ConstString(symbol_name + ((symbol_name[0] == '_') ? 1 : 0)));
   } else
 type = eSymbolTypeUndefined;
 } break;
@@ -6898,10 +6897,9 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
 }
 uint32_t imgcount = m_data.GetU32(&offset);
 uint64_t entries_fileoff = m_data.GetU64(&offset);
-/* leaving the following dead code as comments for spec documentation
-offset += 4; // uint32_t entries_size;
-offset += 4; // uint32_t unused;
-*/
+// 'entries_size' is not used, nor is the 'unused' entry.
+//  offset += 4; // uint32_t entries_size;
+//  offset += 4; // uint32_t unused;
 
 offset = entries_fileoff;
 for (uint32_t i = 0; i < imgcount; i++) {



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 3934a31 - [LLDB][NFC] Reliability fixes for IOHandlerCursesGUI

2022-08-11 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-11T21:10:53-07:00
New Revision: 3934a31cfa024edfaa406c3706dc943e59f9049c

URL: 
https://github.com/llvm/llvm-project/commit/3934a31cfa024edfaa406c3706dc943e59f9049c
DIFF: 
https://github.com/llvm/llvm-project/commit/3934a31cfa024edfaa406c3706dc943e59f9049c.diff

LOG: [LLDB][NFC] Reliability fixes for IOHandlerCursesGUI

- checking retval of function calls
- dead code removal
- null dereference fix

Differential Revision: https://reviews.llvm.org/D131615

Added: 


Modified: 
lldb/source/Core/IOHandlerCursesGUI.cpp

Removed: 




diff  --git a/lldb/source/Core/IOHandlerCursesGUI.cpp 
b/lldb/source/Core/IOHandlerCursesGUI.cpp
index f96073ab698cb..c37c8106224fd 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -3500,19 +3500,19 @@ class ProcessLaunchFormDelegate : public FormDelegate {
 
 FileAction action;
 if (m_standard_input_field->IsSpecified()) {
-  action.Open(STDIN_FILENO, m_standard_input_field->GetFileSpec(), true,
-  false);
-  launch_info.AppendFileAction(action);
+  if (action.Open(STDIN_FILENO, m_standard_input_field->GetFileSpec(), 
true,
+  false))
+launch_info.AppendFileAction(action);
 }
 if (m_standard_output_field->IsSpecified()) {
-  action.Open(STDOUT_FILENO, m_standard_output_field->GetFileSpec(), false,
-  true);
-  launch_info.AppendFileAction(action);
+  if (action.Open(STDOUT_FILENO, m_standard_output_field->GetFileSpec(),
+  false, true))
+launch_info.AppendFileAction(action);
 }
 if (m_standard_error_field->IsSpecified()) {
-  action.Open(STDERR_FILENO, m_standard_error_field->GetFileSpec(), false,
-  true);
-  launch_info.AppendFileAction(action);
+  if (action.Open(STDERR_FILENO, m_standard_error_field->GetFileSpec(),
+  false, true))
+launch_info.AppendFileAction(action);
 }
   }
 
@@ -6821,7 +6821,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
 bool set_selected_line_to_pc = false;
 
 if (update_location) {
-  const bool process_alive = process ? process->IsAlive() : false;
+  const bool process_alive = process->IsAlive();
   bool thread_changed = false;
   if (process_alive) {
 thread = exe_ctx.GetThreadPtr();
@@ -7209,8 +7209,10 @@ class SourceFileWindowDelegate : public WindowDelegate {
   window.Printf("%*s", desc_x - window.GetCursorX(), "");
 window.MoveCursor(window_width - stop_description_len - 15,
   line_y);
-window.PrintfTruncated(1, "<<< Thread %u: %s ",
-   thread->GetIndexID(), stop_description);
+if (thread)
+  window.PrintfTruncated(1, "<<< Thread %u: %s ",
+ thread->GetIndexID(),
+ stop_description);
   }
 } else {
   window.Printf("%*s", window_width - window.GetCursorX() - 1, "");



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] fa51243 - [LLDB][NFC] Reliability Fixes for FormatEntity

2022-08-15 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-15T10:16:47-07:00
New Revision: fa5124327a01ef060f2c5a301e9600892bb63280

URL: 
https://github.com/llvm/llvm-project/commit/fa5124327a01ef060f2c5a301e9600892bb63280
DIFF: 
https://github.com/llvm/llvm-project/commit/fa5124327a01ef060f2c5a301e9600892bb63280.diff

LOG: [LLDB][NFC] Reliability Fixes for FormatEntity

 - Remove dead code
 - Fix incorrect null-reference check

Differential Revision: https://reviews.llvm.org/D131850

Added: 


Modified: 
lldb/source/Core/FormatEntity.cpp

Removed: 




diff  --git a/lldb/source/Core/FormatEntity.cpp 
b/lldb/source/Core/FormatEntity.cpp
index 0ac8fcabc61b..41c4aba63825 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -711,9 +711,6 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
 return false;
   }
 
-  if (valobj == nullptr)
-return false;
-
   ValueObject::ExpressionPathAftermath what_next =
   (do_deref_pointer ? ValueObject::eExpressionPathAftermathDereference
 : ValueObject::eExpressionPathAftermathNothing);
@@ -1695,7 +1692,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
   llvm::StringRef var_representation;
   const char *var_name = var_value_sp->GetName().GetCString();
   if (var_value_sp->GetCompilerType().IsValid()) {
-if (var_value_sp && exe_scope->CalculateTarget())
+if (exe_scope && exe_scope->CalculateTarget())
   var_value_sp =
   var_value_sp->GetQualifiedRepresentationIfAvailable(
   exe_scope->CalculateTarget()



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 1fe7200 - [LLDB][NFC] Fix memory leak in IntstumentationRuntimeTSan.cpp

2022-08-16 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-16T14:34:50-07:00
New Revision: 1fe72001e8d69cae1975a360fee055c2fd3730f4

URL: 
https://github.com/llvm/llvm-project/commit/1fe72001e8d69cae1975a360fee055c2fd3730f4
DIFF: 
https://github.com/llvm/llvm-project/commit/1fe72001e8d69cae1975a360fee055c2fd3730f4.diff

LOG: [LLDB][NFC] Fix memory leak in IntstumentationRuntimeTSan.cpp

ConvertToStructuredArray() relies on its caller to deallocate the 
heap-allocated object pointer it returns. One of its call-sites, in 
GetRenumberedThreadIds(), fails to deallocate causing a memory/resource leak. 
Fix the memory leak by converting the return type to shared_ptr, and clean up 
the rest of the file to use the typedef-ed shared_ptr types for StructuredData 
for safety and consistency.

Differential Revision: https://reviews.llvm.org/D131900

Added: 


Modified: 

lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
 
b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
index 55ef3d245411f..910992c48a7dc 100644
--- 
a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ 
b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -206,10 +206,10 @@ for (int i = 0; i < t.unique_tid_count; i++) {
 t;
 )";
 
-static StructuredData::Array *
+static StructuredData::ArraySP
 CreateStackTrace(ValueObjectSP o,
  const std::string &trace_item_name = ".trace") {
-  StructuredData::Array *trace = new StructuredData::Array();
+  auto trace_sp = std::make_shared();
   ValueObjectSP trace_value_object =
   o->GetValueForExpressionPath(trace_item_name.c_str());
   size_t count = trace_value_object->GetNumChildren();
@@ -218,18 +218,18 @@ CreateStackTrace(ValueObjectSP o,
 trace_value_object->GetChildAtIndex(j, true)->GetValueAsUnsigned(0);
 if (trace_addr == 0)
   break;
-trace->AddItem(
-StructuredData::ObjectSP(new StructuredData::Integer(trace_addr)));
+trace_sp->AddItem(std::make_shared(trace_addr));
   }
-  return trace;
+  return trace_sp;
 }
 
-static StructuredData::Array *ConvertToStructuredArray(
+static StructuredData::ArraySP ConvertToStructuredArray(
 ValueObjectSP return_value_sp, const std::string &items_name,
 const std::string &count_name,
-std::function 
const
+std::function const
 &callback) {
-  StructuredData::Array *array = new StructuredData::Array();
+  auto array_sp = std::make_shared();
   unsigned int count =
   return_value_sp->GetValueForExpressionPath(count_name.c_str())
   ->GetValueAsUnsigned(0);
@@ -237,13 +237,13 @@ static StructuredData::Array *ConvertToStructuredArray(
   return_value_sp->GetValueForExpressionPath(items_name.c_str());
   for (unsigned int i = 0; i < count; i++) {
 ValueObjectSP o = objects->GetChildAtIndex(i, true);
-StructuredData::Dictionary *dict = new StructuredData::Dictionary();
+auto dict_sp = std::make_shared();
 
-callback(o, dict);
+callback(o, dict_sp);
 
-array->AddItem(StructuredData::ObjectSP(dict));
+array_sp->AddItem(dict_sp);
   }
-  return array;
+  return array_sp;
 }
 
 static std::string RetrieveString(ValueObjectSP return_value_sp,
@@ -263,8 +263,8 @@ GetRenumberedThreadIds(ProcessSP process_sp, ValueObjectSP 
data,
std::map &thread_id_map) {
   ConvertToStructuredArray(
   data, ".threads", ".thread_count",
-  [process_sp, &thread_id_map](ValueObjectSP o,
-   StructuredData::Dictionary *dict) {
+  [process_sp, &thread_id_map](const ValueObjectSP &o,
+   const StructuredData::DictionarySP &dict) {
 uint64_t thread_id =
 o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0);
 uint64_t thread_os_id =
@@ -338,31 +338,33 @@ StructuredData::ObjectSP 
InstrumentationRuntimeTSan::RetrieveReportData(
   std::map thread_id_map;
   GetRenumberedThreadIds(process_sp, main_value, thread_id_map);
 
-  StructuredData::Dictionary *dict = new StructuredData::Dictionary();
+  auto dict = std::make_shared();
   dict->AddStringItem("instrumentation_class", "ThreadSanitizer");
   dict->AddStringItem("issue_type",
   RetrieveString(main_value, process_sp, ".description"));
   dict->AddIntegerItem("report_count",
main_value->GetValueForExpressionPath(".report_count")
->GetValueAsUnsigned(0));
-  dict->AddItem("sleep_trace", StructuredData::ObjectSP(CreateStackTrace(
-   main_value, ".sleep_trace")));
+  dict->AddItem("sleep_trace", CreateStackTrace(
+   main_value, ".sleep_trace"));
 
-  StructuredData::Array

[Lldb-commits] [lldb] 461b410 - [LLDB][NFC] Fix optons parsing and misc. reliability in CommandObjectThread

2022-08-16 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-16T15:30:25-07:00
New Revision: 461b410159426fdc6da77e0fb653737e04e0ebe9

URL: 
https://github.com/llvm/llvm-project/commit/461b410159426fdc6da77e0fb653737e04e0ebe9
DIFF: 
https://github.com/llvm/llvm-project/commit/461b410159426fdc6da77e0fb653737e04e0ebe9.diff

LOG: [LLDB][NFC] Fix optons parsing and misc. reliability in CommandObjectThread

* Improve reliability by checking return results for calls to 
FindLineEntryByAddress()
* Fix broken option parsing in SetOptionValue()

Differential Revision: https://reviews.llvm.org/D131983

Added: 


Modified: 
lldb/source/Commands/CommandObjectThread.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectThread.cpp 
b/lldb/source/Commands/CommandObjectThread.cpp
index 5d7f3c16f3894..1e317d8bfdbe8 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -62,15 +62,13 @@ class CommandObjectThreadBacktrace : public 
CommandObjectIterateOverThreads {
   const int short_option = m_getopt_table[option_idx].val;
 
   switch (short_option) {
-  case 'c': {
-int32_t input_count = 0;
-if (option_arg.getAsInteger(0, m_count)) {
+  case 'c':
+if (option_arg.getAsInteger(0, m_count) || (m_count < 0)) {
   m_count = UINT32_MAX;
   error.SetErrorStringWithFormat(
   "invalid integer value for option '%c'", short_option);
-} else if (input_count < 0)
-  m_count = UINT32_MAX;
-  } break;
+}
+break;
   case 's':
 if (option_arg.getAsInteger(0, m_start))
   error.SetErrorStringWithFormat(
@@ -1004,8 +1002,15 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
 
 AddressRange fun_addr_range = sc.function->GetAddressRange();
 Address fun_start_addr = fun_addr_range.GetBaseAddress();
-line_table->FindLineEntryByAddress(fun_start_addr, function_start,
-   &index_ptr);
+
+if (!line_table->FindLineEntryByAddress(fun_start_addr, function_start,
+&index_ptr)) {
+  result.AppendErrorWithFormat(
+  "Failed to find line entry by address for "
+  "frame %u of thread id %" PRIu64 ".\n",
+  m_options.m_frame_idx, thread->GetID());
+  return false;
+}
 
 Address fun_end_addr(fun_start_addr.GetSection(),
  fun_start_addr.GetOffset() +
@@ -1013,8 +1018,14 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
 
 bool all_in_function = true;
 
-line_table->FindLineEntryByAddress(fun_end_addr, function_start,
-   &end_ptr);
+if (!line_table->FindLineEntryByAddress(fun_end_addr, function_start,
+&end_ptr)) {
+  result.AppendErrorWithFormat(
+  "Failed to find line entry by address for "
+  "frame %u of thread id %" PRIu64 ".\n",
+  m_options.m_frame_idx, thread->GetID());
+  return false;
+}
 
 // Since not all source lines will contribute code, check if we are
 // setting the breakpoint on the exact line number or the nearest



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 1633190 - [LLDB][NFC] Fix optons parsing and misc. reliability in CommandObjectThread

2022-08-17 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-17T12:20:10-07:00
New Revision: 163319070947a51beed9d3773bf53d3d48120db8

URL: 
https://github.com/llvm/llvm-project/commit/163319070947a51beed9d3773bf53d3d48120db8
DIFF: 
https://github.com/llvm/llvm-project/commit/163319070947a51beed9d3773bf53d3d48120db8.diff

LOG: [LLDB][NFC] Fix optons parsing and misc. reliability in CommandObjectThread

* Fix broken option parsing in SetOptionValue()

Differential Revision: https://reviews.llvm.org/D131983

Added: 


Modified: 
lldb/source/Commands/CommandObjectThread.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectThread.cpp 
b/lldb/source/Commands/CommandObjectThread.cpp
index 5d7f3c16f3894..7b739fef0a7a4 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -62,15 +62,13 @@ class CommandObjectThreadBacktrace : public 
CommandObjectIterateOverThreads {
   const int short_option = m_getopt_table[option_idx].val;
 
   switch (short_option) {
-  case 'c': {
-int32_t input_count = 0;
-if (option_arg.getAsInteger(0, m_count)) {
+  case 'c':
+if (option_arg.getAsInteger(0, m_count) || (m_count < 0)) {
   m_count = UINT32_MAX;
   error.SetErrorStringWithFormat(
   "invalid integer value for option '%c'", short_option);
-} else if (input_count < 0)
-  m_count = UINT32_MAX;
-  } break;
+}
+break;
   case 's':
 if (option_arg.getAsInteger(0, m_start))
   error.SetErrorStringWithFormat(
@@ -991,7 +989,7 @@ class CommandObjectThreadUntil : public CommandObjectParsed 
{
 }
 
 LineEntry function_start;
-uint32_t index_ptr = 0, end_ptr;
+uint32_t index_ptr = 0, end_ptr = UINT32_MAX;
 std::vector address_list;
 
 // Find the beginning & end index of the function, but first make



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 5a19777 - [LLDB][NFC] Suppress spurious static inspection warnings

2022-08-17 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-08-17T16:12:42-07:00
New Revision: 5a197772ee3077e7bfa2eb3d047d4f36a28b0f39

URL: 
https://github.com/llvm/llvm-project/commit/5a197772ee3077e7bfa2eb3d047d4f36a28b0f39
DIFF: 
https://github.com/llvm/llvm-project/commit/5a197772ee3077e7bfa2eb3d047d4f36a28b0f39.diff

LOG: [LLDB][NFC] Suppress spurious static inspection warnings

Suppress coverity false positives.
This diff contains comments only, including the hints for Coverity static code 
inspection
to suppress the warning originating at the next line after the comment.

Differential Revision: https://reviews.llvm.org/D131998

Added: 


Modified: 
lldb/include/lldb/Core/ThreadSafeValue.h
lldb/source/Host/common/ProcessRunLock.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_riscv64.cpp

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/tools/lldb-vscode/FifoFiles.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/ThreadSafeValue.h 
b/lldb/include/lldb/Core/ThreadSafeValue.h
index 979f008b3170d..ddd7b56e82cef 100644
--- a/lldb/include/lldb/Core/ThreadSafeValue.h
+++ b/lldb/include/lldb/Core/ThreadSafeValue.h
@@ -42,6 +42,7 @@ template  class ThreadSafeValue {
 
   // Call this if you have already manually locked the mutex using the
   // GetMutex() accessor
+  // coverity[missing_lock]
   void SetValueNoLock(const T &value) { m_value = value; }
 
   std::recursive_mutex &GetMutex() { return m_mutex; }

diff  --git a/lldb/source/Host/common/ProcessRunLock.cpp 
b/lldb/source/Host/common/ProcessRunLock.cpp
index aee15779d9199..da59f40576978 100644
--- a/lldb/source/Host/common/ProcessRunLock.cpp
+++ b/lldb/source/Host/common/ProcessRunLock.cpp
@@ -24,6 +24,7 @@ ProcessRunLock::~ProcessRunLock() {
 bool ProcessRunLock::ReadTryLock() {
   ::pthread_rwlock_rdlock(&m_rwlock);
   if (!m_running) {
+// coverity[missing_unlock]
 return true;
   }
   ::pthread_rwlock_unlock(&m_rwlock);

diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index dbf3afff7b0da..c69e7e41248fa 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6345,6 +6345,7 @@ static offset_t CreateAllImageInfosPayload(
 // The segment name in a Mach-O LC_SEGMENT/LC_SEGMENT_64 is char[16] 
and
 // is not guaranteed to be nul-terminated if all 16 characters are
 // used.
+// coverity[buffer_size_warning]
 strncpy(seg_vmaddr.segname, name.AsCString(),
 sizeof(seg_vmaddr.segname));
 seg_vmaddr.vmaddr = vmaddr;
@@ -6740,6 +6741,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
   // the right one, doesn't need to be nul terminated.
   // LC_NOTE name field is char[16] and is not guaranteed to be
   // nul-terminated.
+  // coverity[buffer_size_warning]
   strncpy(namebuf, lcnote->name.c_str(), sizeof(namebuf));
   buffer.PutRawBytes(namebuf, sizeof(namebuf));
   buffer.PutHex64(lcnote->payload_file_offset);

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h 
b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
index 7f7c3ee90c6b8..4c52de99fde63 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
@@ -105,6 +105,7 @@ class RegisterInfoPOSIX_arm64
   uint32_t ConfigureVectorLength(uint32_t sve_vq);
 
   bool VectorSizeIsValid(uint32_t vq) {
+// coverity[unsigned_compare]
 if (vq >= eVectorQuadwordAArch64 && vq <= eVectorQuadwordAArch64SVEMax)
   return true;
 return false;

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_riscv64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_riscv64.cpp
index 06c4e8ec68537..619f30690 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_riscv64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_riscv64.cpp
@@ -126,6 +126,7 @@ size_t RegisterInfoPOSIX_riscv64::GetRegisterSetCount() 
const {
 
 size_t RegisterInfoPOSIX_riscv64::GetRegisterSetFromRegisterIndex(
 uint32_t reg_index) const {
+  // coverity[unsigned_compare]
   if (reg_index >= gpr_first_riscv && reg_index <= gpr_last_riscv)
 return GPRegSet;
   if (reg_index >= fpr_first_riscv && reg_index <= fpr_last_riscv)

diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index f750ad98b593e..1aa1ecc85069d 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteComm