Skip to content

Commit 0910e17

Browse files
committed
[Disassembler] Simplify a few methods (2/2) (NFC)
Use early returns to highlight preconditions and make the code easier to follow. llvm-svn: 370998
1 parent b78324f commit 0910e17

File tree

1 file changed

+62
-52
lines changed

1 file changed

+62
-52
lines changed

lldb/source/Core/Disassembler.cpp

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -244,27 +244,28 @@ bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
244244
bool mixed_source_and_assembly,
245245
uint32_t num_mixed_context_lines,
246246
uint32_t options, Stream &strm) {
247-
if (disasm_range.GetByteSize()) {
248-
lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget(
249-
exe_ctx.GetTargetSP(), arch, flavor, plugin_name));
250-
251-
if (disasm_sp) {
252-
AddressRange range;
253-
ResolveAddress(exe_ctx, disasm_range.GetBaseAddress(),
254-
range.GetBaseAddress());
255-
range.SetByteSize(disasm_range.GetByteSize());
256-
const bool prefer_file_cache = false;
257-
size_t bytes_disassembled = disasm_sp->ParseInstructions(
258-
&exe_ctx, range, &strm, prefer_file_cache);
259-
if (bytes_disassembled == 0)
260-
return false;
261-
262-
return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx,
263-
num_instructions, mixed_source_and_assembly,
264-
num_mixed_context_lines, options, strm);
265-
}
266-
}
267-
return false;
247+
if (!disasm_range.GetByteSize())
248+
return false;
249+
250+
lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget(
251+
exe_ctx.GetTargetSP(), arch, flavor, plugin_name));
252+
253+
if (!disasm_sp)
254+
return false;
255+
256+
AddressRange range;
257+
ResolveAddress(exe_ctx, disasm_range.GetBaseAddress(),
258+
range.GetBaseAddress());
259+
range.SetByteSize(disasm_range.GetByteSize());
260+
const bool prefer_file_cache = false;
261+
size_t bytes_disassembled =
262+
disasm_sp->ParseInstructions(&exe_ctx, range, &strm, prefer_file_cache);
263+
if (bytes_disassembled == 0)
264+
return false;
265+
266+
return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx,
267+
num_instructions, mixed_source_and_assembly,
268+
num_mixed_context_lines, options, strm);
268269
}
269270

270271
bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
@@ -275,42 +276,51 @@ bool Disassembler::Disassemble(Debugger &debugger, const ArchSpec &arch,
275276
bool mixed_source_and_assembly,
276277
uint32_t num_mixed_context_lines,
277278
uint32_t options, Stream &strm) {
278-
if (num_instructions > 0) {
279-
lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget(
280-
exe_ctx.GetTargetSP(), arch, flavor, plugin_name));
281-
if (disasm_sp) {
282-
Address addr;
283-
ResolveAddress(exe_ctx, start_address, addr);
284-
const bool prefer_file_cache = false;
285-
size_t bytes_disassembled = disasm_sp->ParseInstructions(
286-
&exe_ctx, addr, num_instructions, prefer_file_cache);
287-
if (bytes_disassembled == 0)
288-
return false;
289-
return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx,
290-
num_instructions, mixed_source_and_assembly,
291-
num_mixed_context_lines, options, strm);
292-
}
293-
}
294-
return false;
279+
if (num_instructions == 0)
280+
return false;
281+
282+
lldb::DisassemblerSP disasm_sp(Disassembler::FindPluginForTarget(
283+
exe_ctx.GetTargetSP(), arch, flavor, plugin_name));
284+
if (!disasm_sp)
285+
return false;
286+
287+
Address addr;
288+
ResolveAddress(exe_ctx, start_address, addr);
289+
290+
const bool prefer_file_cache = false;
291+
size_t bytes_disassembled = disasm_sp->ParseInstructions(
292+
&exe_ctx, addr, num_instructions, prefer_file_cache);
293+
if (bytes_disassembled == 0)
294+
return false;
295+
296+
return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx,
297+
num_instructions, mixed_source_and_assembly,
298+
num_mixed_context_lines, options, strm);
295299
}
296300

297301
Disassembler::SourceLine
298302
Disassembler::GetFunctionDeclLineEntry(const SymbolContext &sc) {
303+
if (!sc.function)
304+
return {};
305+
306+
if (!sc.line_entry.IsValid())
307+
return {};
308+
309+
LineEntry prologue_end_line = sc.line_entry;
310+
FileSpec func_decl_file;
311+
uint32_t func_decl_line;
312+
sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line);
313+
314+
if (func_decl_file != prologue_end_line.file &&
315+
func_decl_file != prologue_end_line.original_file)
316+
return {};
317+
299318
SourceLine decl_line;
300-
if (sc.function && sc.line_entry.IsValid()) {
301-
LineEntry prologue_end_line = sc.line_entry;
302-
FileSpec func_decl_file;
303-
uint32_t func_decl_line;
304-
sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line);
305-
if (func_decl_file == prologue_end_line.file ||
306-
func_decl_file == prologue_end_line.original_file) {
307-
decl_line.file = func_decl_file;
308-
decl_line.line = func_decl_line;
309-
// TODO do we care about column on these entries? If so, we need to
310-
// plumb that through GetStartLineSourceInfo.
311-
decl_line.column = 0;
312-
}
313-
}
319+
decl_line.file = func_decl_file;
320+
decl_line.line = func_decl_line;
321+
// TODO: Do we care about column on these entries? If so, we need to plumb
322+
// that through GetStartLineSourceInfo.
323+
decl_line.column = 0;
314324
return decl_line;
315325
}
316326

0 commit comments

Comments
 (0)