1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

HackStudio: Use new format functions.

This commit is contained in:
asynts 2020-10-08 13:41:36 +02:00 committed by Andreas Kling
parent 3b601cd4bd
commit 7c4fb2b804
23 changed files with 112 additions and 117 deletions

View file

@ -59,7 +59,7 @@ Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(const Debug::
do {
String name = debug_session.debug_info().name_of_containing_function(current_instruction);
if (name.is_null()) {
dbg() << "BacktraceModel: couldn't find containing function for address: " << (void*)current_instruction;
dbgln("BacktraceModel: couldn't find containing function for address: {:p}", current_instruction);
name = "<missing>";
}

View file

@ -164,7 +164,7 @@ void DebugInfoWidget::update_state(const Debug::DebugSession& debug_session, con
}
auto selected_index = m_backtrace_view->model()->index(0);
if (!selected_index.is_valid()) {
dbg() << "Warning: DebugInfoWidget: backtrace selected index is invalid";
dbgln("Warning: DebugInfoWidget: backtrace selected index is invalid");
return;
}
m_backtrace_view->selection().set(selected_index);

View file

@ -78,7 +78,7 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
auto address = session->debug_info().get_instruction_from_source(position.file_path, position.line_number);
if (!address.has_value()) {
dbg() << "Warning: couldn't get instruction address from source";
dbgln("Warning: couldn't get instruction address from source");
// TODO: Currently, the GUI will indicate that a breakpoint was inserted/removed at this line,
// regardless of whether we actually succeeded to insert it. (For example a breakpoint on a comment, or an include statement).
// We should indicate failure via a return value from this function, and not update the breakpoint GUI if we fail.
@ -97,7 +97,7 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
Debug::DebugInfo::SourcePosition Debugger::create_source_position(const String& file, size_t line)
{
if (!file.starts_with('/') && !file.starts_with("./"))
return { String::format("./%s", file.characters()), line + 1 };
return { String::formatted("./{}", file), line + 1 };
return { file, line + 1 };
}
@ -113,13 +113,13 @@ void Debugger::start()
ASSERT(!!m_debug_session);
for (const auto& breakpoint : m_breakpoints) {
dbg() << "insertig breakpoint at: " << breakpoint.file_path << ":" << breakpoint.line_number;
dbgln("insertig breakpoint at: {}:{}", breakpoint.file_path, breakpoint.line_number);
auto address = m_debug_session->debug_info().get_instruction_from_source(breakpoint.file_path, breakpoint.line_number);
if (address.has_value()) {
bool success = m_debug_session->insert_breakpoint(reinterpret_cast<void*>(address.value()));
ASSERT(success);
} else {
dbg() << "couldn't insert breakpoint";
dbgln("couldn't insert breakpoint");
}
}
@ -132,7 +132,7 @@ int Debugger::debugger_loop()
m_debug_session->run([this](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) {
if (reason == Debug::DebugSession::DebugBreakReason::Exited) {
dbg() << "Program exited";
dbgln("Program exited");
m_on_exit_callback();
return Debug::DebugSession::DebugDecision::Detach;
}
@ -183,7 +183,7 @@ int Debugger::debugger_loop()
// NOTE: Is detaching from the debuggee the best thing to do here?
// We could display a dialog in the UI, remind the user that there is
// a live debugged process, and ask whether they want to terminate/detach.
dbg() << "Debugger exiting";
dbgln("Debugger exiting");
return Debug::DebugSession::DebugDecision::Detach;
}
ASSERT_NOT_REACHED();

View file

@ -40,7 +40,7 @@ DisassemblyModel::DisassemblyModel(const Debug::DebugSession& debug_session, con
{
auto containing_function = debug_session.debug_info().get_containing_function(regs.eip);
if (!containing_function.has_value()) {
dbg() << "Cannot disassemble as the containing function was not found.";
dbgln("Cannot disassemble as the containing function was not found.");
return;
}
@ -110,12 +110,11 @@ GUI::Variant DisassemblyModel::data(const GUI::ModelIndex& index, GUI::ModelRole
if (role == GUI::ModelRole::Display) {
if (index.column() == Column::Address)
return String::format("%#08x", insn.address);
return String::formatted("{:p}", insn.address);
if (index.column() == Column::InstructionBytes) {
StringBuilder builder;
for (auto ch : insn.bytes) {
builder.appendf("%02x ", (u8)ch);
}
for (auto ch : insn.bytes)
builder.appendff("{:02x} ", static_cast<unsigned char>(ch));
return builder.to_string();
}
if (index.column() == Column::Disassembly)

View file

@ -107,7 +107,7 @@ GUI::Variant RegistersModel::data(const GUI::ModelIndex& index, GUI::ModelRole r
if (index.column() == Column::Register)
return reg.name;
if (index.column() == Column::Value)
return String::format("%#08x", reg.value);
return String::formatted("{:08x}", reg.value);
return {};
}
return {};

View file

@ -84,19 +84,19 @@ static String variable_value_as_string(const Debug::DebugInfo::VariableInfo& var
return enumerator->constant_data.as_u32 == enumerator_value;
});
ASSERT(!it.is_end());
return String::format("%s::%s", variable.type_name.characters(), (*it)->name.characters());
return String::formatted("{}::{}", variable.type_name, (*it)->name);
}
if (variable.type_name == "int") {
auto value = Debugger::the().session()->peek((u32*)variable_address);
ASSERT(value.has_value());
return String::format("%d", static_cast<int>(value.value()));
return String::formatted("{}", static_cast<int>(value.value()));
}
if (variable.type_name == "char") {
auto value = Debugger::the().session()->peek((u32*)variable_address);
ASSERT(value.has_value());
return String::format("'%c' (%d)", static_cast<char>(value.value()), static_cast<char>(value.value()));
return String::formatted("'{0:c}' ({0:d})", value.value());
}
if (variable.type_name == "bool") {
@ -105,13 +105,13 @@ static String variable_value_as_string(const Debug::DebugInfo::VariableInfo& var
return (value.value() & 1) ? "true" : "false";
}
return String::format("type: %s @ %08x, ", variable.type_name.characters(), variable_address);
return String::formatted("type: {} @ {:p}, ", variable.type_name, variable_address);
}
static Optional<u32> string_to_variable_value(const StringView& string_value, const Debug::DebugInfo::VariableInfo& variable)
{
if (variable.is_enum_type()) {
auto prefix_string = String::format("%s::", variable.type_name.characters());
auto prefix_string = String::formatted("{}::", variable.type_name);
auto string_to_use = string_value;
if (string_value.starts_with(prefix_string))
string_to_use = string_value.substring_view(prefix_string.length(), string_value.length() - prefix_string.length());
@ -155,8 +155,9 @@ void VariablesModel::set_variable_value(const GUI::ModelIndex& index, const Stri
return;
}
GUI::MessageBox::show(parent_window,
String::format("String value \"%s\" could not be converted to a value of type %s.", string_value.to_string().characters(), variable->type_name.characters()),
GUI::MessageBox::show(
parent_window,
String::formatted("String value \"{}\" could not be converted to a value of type {}.", string_value, variable->type_name),
"Set value failed",
GUI::MessageBox::Type::Error);
}
@ -167,7 +168,7 @@ GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, GUI::ModelRole r
switch (role) {
case GUI::ModelRole::Display: {
auto value_as_string = variable_value_as_string(*variable);
return String::format("%s: %s", variable->name.characters(), value_as_string.characters());
return String::formatted("{}: {}", variable->name, value_as_string);
}
case GUI::ModelRole::Icon:
return m_variable_icon;