Skip to content

Commit

Permalink
[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity sc…
Browse files Browse the repository at this point in the history
…an. 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
  • Loading branch information
fixathon committed Jul 26, 2022
1 parent 2aab797 commit 4871dfc
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &note : notes) {
llvm::StringRef name = note.info.n_name;
Expand Down Expand Up @@ -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 &note : notes) {
// OpenBSD per-thread information is stored in notes named "OpenBSD@nnn" so
// match on the initial part of the string.
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Symbol/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 8 additions & 7 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp,
m_profile_data_comm_mutex(), m_profile_data(), m_iohandler_sync(0),
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_private_run_lock(), m_currently_handling_do_on_removals(false),
m_resume_requested(false), 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(),
Expand Down Expand Up @@ -2566,8 +2567,8 @@ Status Process::LaunchPrivate(ProcessLaunchInfo &launch_info, StateType &state,

if (state == eStateStopped || state == eStateCrashed) {
DidLaunch();
// Now that we know the process type, update its signal responses from the

// Now that we know the process type, update its signal responses from the
// ones stored in the Target:
if (m_unix_signals_sp) {
StreamSP warning_strm = GetTarget().GetDebugger().GetAsyncErrorStream();
Expand Down Expand Up @@ -2935,7 +2936,7 @@ void Process::CompleteAttach() {
}
}
}
// Now that we know the process type, update its signal responses from the
// Now that we know the process type, update its signal responses from the
// ones stored in the Target:
if (m_unix_signals_sp) {
StreamSP warning_strm = GetTarget().GetDebugger().GetAsyncErrorStream();
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Target/RegisterContextUnwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions lldb/source/Target/ThreadPlanCallFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -134,7 +137,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(CompilerType()) {}
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Target/ThreadPlanTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/TraceDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4871dfc

Please sign in to comment.