Skip to content

Commit 1bdfa86

Browse files
committed
debugger: nul-terminated string format improvements
* use one argument instead of two * use width to control maximum length * add debugger help text
1 parent 7e3b98d commit 1bdfa86

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/emu/debug/debugcmd.cpp

+17-15
Original file line numberDiff line numberDiff line change
@@ -573,33 +573,35 @@ bool debugger_commands::mini_printf(std::ostream &stream, const std::vector<std:
573573
break;
574574

575575
case 's':
576-
if ((param + 1) < params.size())
577576
{
578-
address_space *space, *tspace;
579-
std::string s;
580-
581-
if (m_console.validate_device_space_parameter(params[param + 0], -1, space) && m_console.validate_number_parameter(params[param + 1], number))
577+
address_space *space;
578+
if (param < params.size() && m_console.validate_target_address_parameter(params[param++], -1, space, number))
582579
{
580+
address_space *tspace;
581+
std::string s;
582+
583583
for (u32 address = u32(number), taddress; space->device().memory().translate(space->spacenum(), device_memory_interface::TR_READ, taddress = address, tspace); address++)
584584
{
585585
u8 const data = tspace->read_byte(taddress);
586586

587-
if (data)
588-
s += data;
589-
else
587+
if (!data)
590588
break;
589+
590+
s += data;
591+
592+
if (width == 1)
593+
break;
594+
else if (width)
595+
width--;
591596
}
592597

593-
util::stream_format(stream, "%*s", width, s);
594-
param += 2;
598+
util::stream_format(stream, "%s", s);
595599
}
596600
else
601+
{
602+
m_console.printf("Not enough parameters for format!\n");
597603
return false;
598-
}
599-
else
600-
{
601-
m_console.printf("Not enough parameters for format!\n");
602-
return false;
604+
}
603605
}
604606
break;
605607
}

src/emu/debug/debughlp.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ const help_item f_static_help_list[] =
361361
"\n"
362362
" %[0][<n>]d -- prints <item> as a decimal value with optional digit count and zero-fill\n"
363363
" %[0][<n>]x -- prints <item> as a hexadecimal value with optional digit count and zero-fill\n"
364+
" %[<n>]s -- prints all or up to <n> non-nul bytes from address and address space given by <item>\n"
364365
"\n"
365366
"All remaining formatting options are ignored. Use %% together to output a % character. Multiple "
366367
"lines can be printed by embedding a \\n in the text.\n"
@@ -383,6 +384,7 @@ const help_item f_static_help_list[] =
383384
"\n"
384385
" %[0][<n>]d -- logs <item> as a decimal value with optional digit count and zero-fill\n"
385386
" %[0][<n>]x -- logs <item> as a hexadecimal value with optional digit count and zero-fill\n"
387+
" %[<n>]s -- logs all or up to <n> non-nul bytes from address and address space given by <item>\n"
386388
"\n"
387389
"All remaining formatting options are ignored. Use %% together to output a % character. Multiple "
388390
"lines can be printed by embedding a \\n in the text.\n"

0 commit comments

Comments
 (0)