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<uint32_t>( 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<llvm::support::ulittle32_t>(stop_info_sp->GetValue()); exp_record.ExceptionFlags = static_cast<llvm::support::ulittle32_t>(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) {} 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 58b4fe3add1b3..24c942f1d290a 100644 --- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp +++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp @@ -610,9 +610,9 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) { // To be extracted from struct netbsd_elfcore_procinfo // Used to sanity check of the LWPs of the process uint32_t nlwps = 0; - uint32_t signo; // killing signal - uint32_t siglwp; // LWP target of killing signal - uint32_t pr_pid; + uint32_t signo = 0; // killing signal + uint32_t siglwp = 0; // LWP target of killing signal + uint32_t pr_pid = 0; for (const auto ¬e : notes) { llvm::StringRef name = note.info.n_name; @@ -764,7 +764,7 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) { } llvm::Error ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef<CoreNote> notes) { - ThreadData thread_data; + ThreadData thread_data = {}; for (const auto ¬e : notes) { // OpenBSD per-thread information is stored in notes named "OpenBSD@nnn" so // match on the initial part of the string. diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp index c91c111d8df3a..64219e1a960b8 100644 --- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp +++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp @@ -233,7 +233,8 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp, const FileSpec &core_file, DataBufferSP core_data) : PostMortemProcess(target_sp, listener_sp), m_core_file(core_file), - m_core_data(std::move(core_data)), m_is_wow64(false) {} + m_core_data(std::move(core_data)), m_active_exception(nullptr), + m_is_wow64(false) {} ProcessMinidump::~ProcessMinidump() { Clear(); diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp index 6317b140f7e8e..7d730ecdd1f33 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp @@ -475,7 +475,7 @@ llvm::StringRef lldb_private::npdb::DropNameScope(llvm::StringRef name) { } VariableInfo lldb_private::npdb::GetVariableNameInfo(CVSymbol sym) { - VariableInfo result; + VariableInfo result = {}; if (sym.kind() == S_REGREL32) { RegRelativeSym reg(SymbolRecordKind::RegRelativeSym); diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp index 2e60ba6f3fc31..7fc1d6ab49ec1 100644 --- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp +++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp @@ -747,7 +747,7 @@ void SystemRuntimeMacOSX::PopulateQueueList( SystemRuntimeMacOSX::PendingItemsForQueue SystemRuntimeMacOSX::GetPendingItemRefsForQueue(lldb::addr_t queue) { - PendingItemsForQueue pending_item_refs; + PendingItemsForQueue pending_item_refs = {}; AppleGetPendingItemsHandler::GetPendingItemsReturnInfo pending_items_pointer; ThreadSP cur_thread_sp( m_process->GetThreadList().GetExpressionExecutionThread()); diff --git a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp index 92eec139e07c9..c796cbc75c1b6 100644 --- a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp +++ b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp @@ -968,7 +968,7 @@ bool x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly( UnwindPlan::RowSP prologue_completed_row; // copy of prologue row of CFI int prologue_completed_sp_bytes_offset_from_cfa; // The sp value before the // epilogue started executed - bool prologue_completed_is_aligned; + bool prologue_completed_is_aligned = false; std::vector<bool> prologue_completed_saved_registers; while (current_func_text_offset < size) { diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp index 4ee5a3e76ae44..f83bdcdc1c740 100644 --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -162,8 +162,8 @@ Type::Type(lldb::user_id_t uid, SymbolFile *symbol_file, ConstString name, } Type::Type() - : std::enable_shared_from_this<Type>(), UserID(0), - m_name("<INVALID TYPE>") { + : std::enable_shared_from_this<Type>(), UserID(0), m_name("<INVALID TYPE>"), + m_payload(0) { m_byte_size = 0; m_byte_size_has_value = false; } diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 0467066376913..6583baec63202 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -434,10 +434,11 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp, m_memory_cache(*this), m_allocated_memory_cache(*this), m_should_detach(false), m_next_event_action_up(), m_public_run_lock(), m_private_run_lock(), m_finalizing(false), - m_clear_thread_plans_on_stop(false), m_force_next_event_delivery(false), - m_last_broadcast_state(eStateInvalid), m_destroy_in_process(false), - m_can_interpret_function_calls(false), m_run_thread_plan_lock(), - m_can_jit(eCanJITDontKnow) { + m_clear_thread_plans_on_stop(false), + m_currently_handling_do_on_removals(false), m_resume_requested(false), + m_force_next_event_delivery(false), m_last_broadcast_state(eStateInvalid), + m_destroy_in_process(false), m_can_interpret_function_calls(false), + m_run_thread_plan_lock(), m_can_jit(eCanJITDontKnow) { CheckInWithManager(); Log *log = GetLog(LLDBLog::Object); @@ -4550,9 +4551,9 @@ class RestorePlanState { private: lldb::ThreadPlanSP m_thread_plan_sp; bool m_already_reset = false; - bool m_private; - bool m_is_controlling; - bool m_okay_to_discard; + bool m_private = false; + bool m_is_controlling = false; + bool m_okay_to_discard = false; }; } // anonymous namespace diff --git a/lldb/source/Target/RegisterContextUnwind.cpp b/lldb/source/Target/RegisterContextUnwind.cpp index a0f97d7e7cff4..2da40ba2bf61e 100644 --- a/lldb/source/Target/RegisterContextUnwind.cpp +++ b/lldb/source/Target/RegisterContextUnwind.cpp @@ -1525,7 +1525,7 @@ RegisterContextUnwind::SavedLocationForRegister( // unwindplan_regloc has valid contents about where to retrieve the register if (unwindplan_regloc.IsUnspecified()) { - lldb_private::UnwindLLDB::RegisterLocation new_regloc; + lldb_private::UnwindLLDB::RegisterLocation new_regloc = {}; new_regloc.type = UnwindLLDB::RegisterLocation::eRegisterNotSaved; m_registers[regnum.GetAsKind(eRegisterKindLLDB)] = new_regloc; UnwindLogMsg("save location for %s (%d) is unspecified, continue searching", @@ -1731,7 +1731,7 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() { addr_t old_caller_pc_value = LLDB_INVALID_ADDRESS; addr_t new_caller_pc_value = LLDB_INVALID_ADDRESS; - UnwindLLDB::RegisterLocation regloc; + UnwindLLDB::RegisterLocation regloc = {}; if (SavedLocationForRegister(pc_regnum.GetAsKind(eRegisterKindLLDB), regloc) == UnwindLLDB::RegisterSearchResult::eRegisterFound) { diff --git a/lldb/source/Target/ThreadPlanCallFunction.cpp b/lldb/source/Target/ThreadPlanCallFunction.cpp index a9f774aa61097..629ffcf307153 100644 --- a/lldb/source/Target/ThreadPlanCallFunction.cpp +++ b/lldb/source/Target/ThreadPlanCallFunction.cpp @@ -104,7 +104,10 @@ ThreadPlanCallFunction::ThreadPlanCallFunction( m_ignore_breakpoints(options.DoesIgnoreBreakpoints()), m_debug_execution(options.GetDebug()), m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function), - m_function_sp(0), m_takedown_done(false), + m_start_addr(), m_function_sp(0), m_subplan_sp(), + m_cxx_language_runtime(nullptr), m_objc_language_runtime(nullptr), + m_stored_thread_state(), m_real_stop_info_sp(), m_constructor_errors(), + m_return_valobj_sp(), m_takedown_done(false), m_should_clear_objc_exception_bp(false), m_should_clear_cxx_exception_bp(false), m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(return_type) { @@ -134,8 +137,11 @@ ThreadPlanCallFunction::ThreadPlanCallFunction( m_ignore_breakpoints(options.DoesIgnoreBreakpoints()), m_debug_execution(options.GetDebug()), m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function), - m_function_sp(0), m_takedown_done(false), - m_should_clear_objc_exception_bp(false), + m_start_addr(), m_function_sp(0), m_subplan_sp(), + m_cxx_language_runtime(nullptr), m_objc_language_runtime(nullptr), + m_stored_thread_state(), m_real_stop_info_sp(), m_constructor_errors(), + m_return_valobj_sp(), m_takedown_done(false), m_function_sp(0), + m_takedown_done(false), m_should_clear_objc_exception_bp(false), m_should_clear_cxx_exception_bp(false), m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {} diff --git a/lldb/source/Target/ThreadPlanTracer.cpp b/lldb/source/Target/ThreadPlanTracer.cpp index f5331428038be..7e09253076443 100644 --- a/lldb/source/Target/ThreadPlanTracer.cpp +++ b/lldb/source/Target/ThreadPlanTracer.cpp @@ -36,11 +36,11 @@ using namespace lldb_private; ThreadPlanTracer::ThreadPlanTracer(Thread &thread, lldb::StreamSP &stream_sp) : m_process(*thread.GetProcess().get()), m_tid(thread.GetID()), - m_enabled(false), m_stream_sp(stream_sp) {} + m_enabled(false), m_stream_sp(stream_sp), m_thread(nullptr) {} ThreadPlanTracer::ThreadPlanTracer(Thread &thread) : m_process(*thread.GetProcess().get()), m_tid(thread.GetID()), - m_enabled(false), m_stream_sp() {} + m_enabled(false), m_stream_sp(), m_thread(nullptr) {} Stream *ThreadPlanTracer::GetLogStream() { if (m_stream_sp) diff --git a/lldb/source/Target/TraceDumper.cpp b/lldb/source/Target/TraceDumper.cpp index 739105e9e9fb1..c9ef3aa5bd6b7 100644 --- a/lldb/source/Target/TraceDumper.cpp +++ b/lldb/source/Target/TraceDumper.cpp @@ -286,7 +286,7 @@ TraceDumper::TraceDumper(lldb::TraceCursorUP &&cursor_up, Stream &s, } TraceDumper::TraceItem TraceDumper::CreatRawTraceItem() { - TraceItem item; + TraceItem item = {}; item.id = m_cursor_up->GetId(); if (m_options.show_tsc) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits