Re: [Lldb-commits] [PATCH] D19086: [clang-analyzer] fix warnings emitted on lldb code base

2016-05-01 Thread Apelete Seketeli via lldb-commits
apelete updated this revision to Diff 55753.
apelete added a comment.

[clang-analyzer] fix warnings emitted on lldb code base

Changes since last revision:

- fast forward rebase on git master branch.


http://reviews.llvm.org/D19086

Files:
  include/lldb/Utility/LLDBAssert.h
  source/API/SBThread.cpp
  source/Core/DynamicLoader.cpp
  source/Core/FormatEntity.cpp
  source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
@@ -468,7 +468,6 @@
 DWARFFormValue encoding_uid;
 uint32_t member_byte_offset = UINT32_MAX;
 DWARFExpression member_location_expression(dwarf_cu);
-bool artificial = true;
 
 DWARFAttributes attributes;
 size_t num_attributes = die.GetAttributes(attributes);
@@ -494,7 +493,7 @@
 member_byte_offset = form_value.Unsigned();
 break;
 case DW_AT_artificial:
-artificial = form_value.Boolean();
+// TODO: Handle when needed
 break;
 case DW_AT_accessibility:
 // TODO: Handle when needed
@@ -506,7 +505,7 @@
 }
 }
 
-if (strcmp(name, ".dynamic_type") == 0)
+if (name && strcmp(name, ".dynamic_type") == 0)
 m_ast.SetDynamicTypeId(compiler_type, member_location_expression);
 else
 {
Index: source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
===
--- source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
+++ source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
@@ -283,8 +283,11 @@
 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
 
 if (!reg_ctx)
+{
 error.SetErrorString("no registers are available");
-
+return error;
+}
+
 DataExtractor data;
 Error data_error;
 size_t num_bytes = new_value_sp->GetData(data, data_error);
@@ -307,6 +310,7 @@
 if (num_bytes <= 16)
 {
 const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+
 if (num_bytes <= 8)
 {
 uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
Index: source/Core/FormatEntity.cpp
===
--- source/Core/FormatEntity.cpp
+++ source/Core/FormatEntity.cpp
@@ -1013,7 +1013,8 @@
 
 if (special_directions.empty())
 {
-success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
+if (item)
+success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
 }
 else
 {
Index: source/Core/DynamicLoader.cpp
===
--- source/Core/DynamicLoader.cpp
+++ source/Core/DynamicLoader.cpp
@@ -194,7 +194,7 @@
 {
 // Try to fetch the load address of the file from the process as we need absolute load
 // address to read the file out of the memory instead of a load bias.
-bool is_loaded;
+bool is_loaded = false;
 lldb::addr_t load_addr;
 Error error = m_process->GetFileLoadAddress(file, is_loaded, load_addr);
 if (error.Success() && is_loaded)
Index: source/API/SBThread.cpp
===
--- source/API/SBThread.cpp
+++ source/API/SBThread.cpp
@@ -923,7 +923,7 @@
 bool abort_other_plans = false;
 bool stop_other_threads = false;
 Thread *thread = exe_ctx.GetThreadPtr();
-if (sb_frame.GetThread().GetThreadID() != thread->GetID())
+if (log && sb_frame.GetThread().GetThreadID() != thread->GetID())
 {
 log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.",
 static_cast(exe_ctx.GetThreadPtr()),
Index: include/lldb/Utility/LLDBAssert.h
===
--- include/lldb/Utility/LLDBAssert.h
+++ include/lldb/Utility/LLDBAssert.h
@@ -24,7 +24,7 @@
  const char* expr_text,
  const char* func,
  const char* file,
- unsigned int line);
+ unsigned int line) __attribute__((__noreturn__));
 }
 
 #endif // utility_LLDBAss

Re: [Lldb-commits] [PATCH] D19086: [clang-analyzer] fix warnings emitted on lldb code base

2016-05-01 Thread Apelete Seketeli via lldb-commits
apelete added a comment.

Waiting for review, could someone please have a look at this one ?


http://reviews.llvm.org/D19086



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


[Lldb-commits] [scan-build] Fix reported dead store, logic error and api bugs

2016-04-03 Thread Apelete Seketeli via lldb-commits
Hello,

Here are a few changes that try to address some logic error bugs
reported by running scan-build over the LLDB code base.

I have no background in compiler technology and I may have been trying
to fix false positives; here is a quick overview of what scan-build
reported, let me know if the fixes are relevant:

Bug Group: Dead store
Bug Type: Dead assignment
Files: source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp

Bug Group: Logic error
Bug Type: Called C++ object pointer is null
Files: source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp

Bug Group: Logic error
Bug Type: Called C++ object pointer is null
Files: source/API/SBThread.cpp

Bug group: Logic error
Bug Type: Branch condition evaluates to a garbage value
Files: source/Core/DynamicLoader.cpp

Bug Group: API
Bug Type: Argument with 'nonnull' attribute passed null
Files: source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp

Cheers.
-- 
Apelete
diff --git a/source/API/SBThread.cpp b/source/API/SBThread.cpp
index 015a42d..34a9f15 100644
--- a/source/API/SBThread.cpp
+++ b/source/API/SBThread.cpp
@@ -960,7 +960,7 @@ SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame)
 bool abort_other_plans = false;
 bool stop_other_threads = false;
 Thread *thread = exe_ctx.GetThreadPtr();
-if (sb_frame.GetThread().GetThreadID() != thread->GetID())
+if (sb_frame.GetThread().GetThreadID() != thread->GetID() && log)
 {
 log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.",
 static_cast(exe_ctx.GetThreadPtr()),
diff --git a/source/Core/DynamicLoader.cpp b/source/Core/DynamicLoader.cpp
index 0edc8c0..f41ff4a 100644
--- a/source/Core/DynamicLoader.cpp
+++ b/source/Core/DynamicLoader.cpp
@@ -194,7 +194,7 @@ DynamicLoader::LoadModuleAtAddress(const FileSpec &file,
 {
 // Try to fetch the load address of the file from the process as we need absolute load
 // address to read the file out of the memory instead of a load bias.
-bool is_loaded;
+bool is_loaded = false;
 lldb::addr_t load_addr;
 Error error = m_process->GetFileLoadAddress(file, is_loaded, load_addr);
 if (error.Success() && is_loaded)
diff --git a/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp b/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
index 7074671..5c92f60 100644
--- a/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
+++ b/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
@@ -306,23 +306,27 @@ ABISysV_mips64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb
 
 if (num_bytes <= 16)
 {
-const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+const RegisterInfo *r2_info = nullptr;
+
+if (reg_ctx)
+  r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+
 if (num_bytes <= 8)
 {
 uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
 
-if (!reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
+if (reg_ctx && !reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
 error.SetErrorString ("failed to write register r2");
 }
 else
 {
 uint64_t raw_value = data.GetMaxU64(&offset, 8);
-if (reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
+if (reg_ctx && reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
 {
 const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
 raw_value = data.GetMaxU64(&offset, num_bytes - offset);
 
-if (!reg_ctx->WriteRegisterFromUnsigned (r3_info, raw_value))
+if (reg_ctx && !reg_ctx->WriteRegisterFromUnsigned (r3_info, raw_value))
 error.SetErrorString ("failed to write register r3");
 }
 else
diff --git a/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp b/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
index 1bb1079..378b84f 100644
--- a/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
+++ b/source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
@@ -468,7 +468,6 @@ DWARFASTParserJava::ParseChildMembers(const DWARFDIE &parent_die, CompilerType &
 DWARFFormValue encoding_uid;
 uint32_t member_byte_offset = UINT32_MAX;
 DWARFExpression member_location_expression(dwarf_cu);
-bool artificial = true;
 
 DWARFAttributes attributes;
 size_t num_attributes = die.GetAttributes(attributes);
@@ -4

[Lldb-commits] [PATCH] D19086: [clang-analyzer] fix warnings emitted on lldb code base

2016-04-13 Thread Apelete Seketeli via lldb-commits
apelete created this revision.
apelete added a subscriber: lldb-commits.

The following warnings were reported while running clang analyzer on
LLDB code base:

API: argument with 'nonnull' attribute passed null, on file:
- source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp.

Dead store: dead assignement, on file:
- source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp.

Logic error: branch condition evaluates to a garbage value, on file:
- source/Core/DynamicLoader.cpp

Logic error: called C++ object pointer is null, on files:
- source/API/SBThread.cpp,
- source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp,
- source/DataFormatters/VectorType.cpp (22 warnings in cpp file,
  suppressed in custom assertion handler in
  include/lldb/Utility/LLDBAssert.h),
- source/Core/FormatEntity.cpp.

(please note that first revision was sent only to lldb-commits mailing
list, not reviewed yet).

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19086

Files:
  include/lldb/Utility/LLDBAssert.h
  source/API/SBThread.cpp
  source/Core/DynamicLoader.cpp
  source/Core/FormatEntity.cpp
  source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
@@ -468,7 +468,6 @@
 DWARFFormValue encoding_uid;
 uint32_t member_byte_offset = UINT32_MAX;
 DWARFExpression member_location_expression(dwarf_cu);
-bool artificial = true;
 
 DWARFAttributes attributes;
 size_t num_attributes = die.GetAttributes(attributes);
@@ -494,7 +493,7 @@
 member_byte_offset = form_value.Unsigned();
 break;
 case DW_AT_artificial:
-artificial = form_value.Boolean();
+// TODO: Handle when needed
 break;
 case DW_AT_accessibility:
 // TODO: Handle when needed
@@ -506,7 +505,7 @@
 }
 }
 
-if (strcmp(name, ".dynamic_type") == 0)
+if (name && strcmp(name, ".dynamic_type") == 0)
 m_ast.SetDynamicTypeId(compiler_type, member_location_expression);
 else
 {
Index: source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
===
--- source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
+++ source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
@@ -306,23 +306,27 @@
 
 if (num_bytes <= 16)
 {
-const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+const RegisterInfo *r2_info = nullptr;
+
+if (reg_ctx)
+  r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+
 if (num_bytes <= 8)
 {
 uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
 
-if (!reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
+if (reg_ctx && !reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
 error.SetErrorString ("failed to write register r2");
 }
 else
 {
 uint64_t raw_value = data.GetMaxU64(&offset, 8);
-if (reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
+if (reg_ctx && reg_ctx->WriteRegisterFromUnsigned (r2_info, raw_value))
 {
 const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
 raw_value = data.GetMaxU64(&offset, num_bytes - offset);
 
-if (!reg_ctx->WriteRegisterFromUnsigned (r3_info, raw_value))
+if (reg_ctx && !reg_ctx->WriteRegisterFromUnsigned (r3_info, raw_value))
 error.SetErrorString ("failed to write register r3");
 }
 else
Index: source/Core/FormatEntity.cpp
===
--- source/Core/FormatEntity.cpp
+++ source/Core/FormatEntity.cpp
@@ -1013,7 +1013,8 @@
 
 if (special_directions.empty())
 {
-success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
+if (item)
+success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
 }
 else
 {
Index: source/Core/DynamicLoader.cpp

Re: [Lldb-commits] [PATCH] D19086: [clang-analyzer] fix warnings emitted on lldb code base

2016-04-14 Thread Apelete Seketeli via lldb-commits
apelete updated this revision to Diff 53774.
apelete added a comment.

[clang-analyzer] fix warnings emitted on lldb code base

Following changes were done in this revision:

- source/API/SBThread.cpp: swith if() statement conditions to branch out early,
- source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp: return early if reg_ctx is 
null.


http://reviews.llvm.org/D19086

Files:
  include/lldb/Utility/LLDBAssert.h
  source/API/SBThread.cpp
  source/Core/DynamicLoader.cpp
  source/Core/FormatEntity.cpp
  source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp

Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
===
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserJava.cpp
@@ -468,7 +468,6 @@
 DWARFFormValue encoding_uid;
 uint32_t member_byte_offset = UINT32_MAX;
 DWARFExpression member_location_expression(dwarf_cu);
-bool artificial = true;
 
 DWARFAttributes attributes;
 size_t num_attributes = die.GetAttributes(attributes);
@@ -494,7 +493,7 @@
 member_byte_offset = form_value.Unsigned();
 break;
 case DW_AT_artificial:
-artificial = form_value.Boolean();
+// TODO: Handle when needed
 break;
 case DW_AT_accessibility:
 // TODO: Handle when needed
@@ -506,7 +505,7 @@
 }
 }
 
-if (strcmp(name, ".dynamic_type") == 0)
+if (name && strcmp(name, ".dynamic_type") == 0)
 m_ast.SetDynamicTypeId(compiler_type, member_location_expression);
 else
 {
Index: source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
===
--- source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
+++ source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp
@@ -283,8 +283,11 @@
 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
 
 if (!reg_ctx)
+{
 error.SetErrorString("no registers are available");
-
+return error;
+}
+
 DataExtractor data;
 Error data_error;
 size_t num_bytes = new_value_sp->GetData(data, data_error);
@@ -307,6 +310,7 @@
 if (num_bytes <= 16)
 {
 const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
+
 if (num_bytes <= 8)
 {
 uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
Index: source/Core/FormatEntity.cpp
===
--- source/Core/FormatEntity.cpp
+++ source/Core/FormatEntity.cpp
@@ -1013,7 +1013,8 @@
 
 if (special_directions.empty())
 {
-success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
+if (item)
+success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
 }
 else
 {
Index: source/Core/DynamicLoader.cpp
===
--- source/Core/DynamicLoader.cpp
+++ source/Core/DynamicLoader.cpp
@@ -194,7 +194,7 @@
 {
 // Try to fetch the load address of the file from the process as we need absolute load
 // address to read the file out of the memory instead of a load bias.
-bool is_loaded;
+bool is_loaded = false;
 lldb::addr_t load_addr;
 Error error = m_process->GetFileLoadAddress(file, is_loaded, load_addr);
 if (error.Success() && is_loaded)
Index: source/API/SBThread.cpp
===
--- source/API/SBThread.cpp
+++ source/API/SBThread.cpp
@@ -923,7 +923,7 @@
 bool abort_other_plans = false;
 bool stop_other_threads = false;
 Thread *thread = exe_ctx.GetThreadPtr();
-if (sb_frame.GetThread().GetThreadID() != thread->GetID())
+if (log && sb_frame.GetThread().GetThreadID() != thread->GetID())
 {
 log->Printf("SBThread(%p)::StepOutOfFrame passed a frame from another thread (0x%" PRIx64 " vrs. 0x%" PRIx64 ", returning.",
 static_cast(exe_ctx.GetThreadPtr()),
Index: include/lldb/Utility/LLDBAssert.h
===
--- include/lldb/Utility/LLDBAssert.h
+++ include/lldb/Utility/LLDBAssert.h
@@ -24,7 +24,7 @@
  const char* expr_text,
  const char* func,
  const char* fil

Re: [Lldb-commits] [PATCH] D19086: [clang-analyzer] fix warnings emitted on lldb code base

2016-04-14 Thread Apelete Seketeli via lldb-commits
apelete marked 2 inline comments as done.
apelete added a comment.

http://reviews.llvm.org/D19086



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


Re: [Lldb-commits] [PATCH] D19086: [clang-analyzer] fix warnings emitted on lldb code base

2016-04-19 Thread Apelete Seketeli via lldb-commits
apelete added a comment.

Ping :).
Requested changes are done, could someone have a look have this one ?


http://reviews.llvm.org/D19086



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