Skip to content

Commit 0524b10

Browse files
committed
emu/debug/debugcmd.cpp: Added support for lowercase hex to printf/logerror. [Patrick Mackinlay]
Also simplified implementation by better leveraging util/strformat.h. This is from pull request #12124, to get some testing for the fundamental change before freeze.
1 parent c545ac9 commit 0524b10

File tree

5 files changed

+54
-73
lines changed

5 files changed

+54
-73
lines changed

Diff for: docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
# built documents.
6464
#
6565
# The short X.Y version.
66-
version = '0.263'
66+
version = '0.264'
6767
# The full version, including alpha/beta/rc tags.
68-
release = '0.263'
68+
release = '0.264'
6969

7070
# The language for content autogenerated by Sphinx. Refer to documentation
7171
# for a list of supported languages.

Diff for: docs/source/debugger/general.rst

+3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ available:
197197
Prints the corresponding argument as an octal number with optional
198198
minimum field width and zero fill using lowercase letters.
199199
%[0][<n>]x
200+
Prints the corresponding argument as a hexadecimal number with
201+
optional minimum field width and zero fill using lowercase letters.
202+
%[0][<n>]X
200203
Prints the corresponding argument as a hexadecimal number with
201204
optional minimum field width and zero fill using uppercase letters.
202205
\%%

Diff for: src/emu/debug/debugcmd.cpp

+34-62
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,14 @@ void debugger_commands::execute_print(const std::vector<std::string_view> &param
469469
mini_printf - safe printf to a buffer
470470
-------------------------------------------------*/
471471

472-
bool debugger_commands::mini_printf(std::ostream &stream, std::string_view format, int params, u64 *param)
472+
bool debugger_commands::mini_printf(std::ostream &stream, const std::vector<std::string_view> &params)
473473
{
474+
std::string_view format(params[0]);
474475
auto f = format.begin();
475476

477+
int param = 1;
478+
u64 number;
479+
476480
// parse the string looking for % signs
477481
while (f != format.end())
478482
{
@@ -517,68 +521,55 @@ bool debugger_commands::mini_printf(std::ostream &stream, std::string_view forma
517521
break;
518522

519523
case 'X':
524+
if (param < params.size() && m_console.validate_number_parameter(params[param++], number))
525+
util::stream_format(stream, zerofill ? "%0*X" : "%*X", width, number);
526+
else
527+
{
528+
m_console.printf("Not enough parameters for format!\n");
529+
return false;
530+
}
531+
break;
520532
case 'x':
521-
if (params == 0)
533+
if (param < params.size() && m_console.validate_number_parameter(params[param++], number))
534+
util::stream_format(stream, zerofill ? "%0*x" : "%*x", width, number);
535+
else
522536
{
523537
m_console.printf("Not enough parameters for format!\n");
524538
return false;
525539
}
526-
if (u32(*param >> 32) != 0)
527-
util::stream_format(stream, zerofill ? "%0*X" : "%*X", (width <= 8) ? 1 : width - 8, u32(*param >> 32));
528-
else if (width > 8)
529-
util::stream_format(stream, zerofill ? "%0*X" : "%*X", width - 8, 0);
530-
util::stream_format(stream, zerofill ? "%0*X" : "%*X", (width < 8) ? width : 8, u32(*param));
531-
param++;
532-
params--;
533540
break;
534541

535542
case 'O':
536543
case 'o':
537-
if (params == 0)
544+
if (param < params.size() && m_console.validate_number_parameter(params[param++], number))
545+
util::stream_format(stream, zerofill ? "%0*o" : "%*o", width, number);
546+
else
538547
{
539548
m_console.printf("Not enough parameters for format!\n");
540549
return false;
541550
}
542-
if (u32(*param >> 60) != 0)
543-
{
544-
util::stream_format(stream, zerofill ? "%0*o" : "%*o", (width <= 20) ? 1 : width - 20, u32(*param >> 60));
545-
util::stream_format(stream, "%0*o", 10, u32(BIT(*param, 30, 30)));
546-
}
547-
else
548-
{
549-
if (width > 20)
550-
util::stream_format(stream, zerofill ? "%0*o" : "%*o", width - 20, 0);
551-
if (u32(BIT(*param, 30, 30)) != 0)
552-
util::stream_format(stream, zerofill ? "%0*o" : "%*o", (width <= 10) ? 1 : width - 10, u32(BIT(*param, 30, 30)));
553-
else if (width > 10)
554-
util::stream_format(stream, zerofill ? "%0*o" : "%*o", width - 10, 0);
555-
}
556-
util::stream_format(stream, zerofill ? "%0*o" : "%*o", (width < 10) ? width : 10, u32(BIT(*param, 0, 30)));
557-
param++;
558-
params--;
559551
break;
560552

561553
case 'D':
562554
case 'd':
563-
if (params == 0)
555+
if (param < params.size() && m_console.validate_number_parameter(params[param++], number))
556+
util::stream_format(stream, zerofill ? "%0*d" : "%*d", width, number);
557+
else
564558
{
565559
m_console.printf("Not enough parameters for format!\n");
566560
return false;
567561
}
568-
util::stream_format(stream, zerofill ? "%0*d" : "%*d", width, u32(*param));
569-
param++;
570-
params--;
571562
break;
563+
572564
case 'C':
573565
case 'c':
574-
if (params == 0)
566+
if (param < params.size() && m_console.validate_number_parameter(params[param++], number))
567+
stream << char(number);
568+
else
575569
{
576570
m_console.printf("Not enough parameters for format!\n");
577571
return false;
578572
}
579-
stream << char(*param);
580-
param++;
581-
params--;
582573
break;
583574

584575
}
@@ -630,15 +621,9 @@ void debugger_commands::execute_index_command(std::vector<std::string_view> cons
630621

631622
void debugger_commands::execute_printf(const std::vector<std::string_view> &params)
632623
{
633-
/* validate the other parameters */
634-
u64 values[MAX_COMMAND_PARAMS];
635-
for (int i = 1; i < params.size(); i++)
636-
if (!m_console.validate_number_parameter(params[i], values[i]))
637-
return;
638-
639624
/* then do a printf */
640625
std::ostringstream buffer;
641-
if (mini_printf(buffer, params[0], params.size() - 1, &values[1]))
626+
if (mini_printf(buffer, params))
642627
m_console.printf("%s\n", std::move(buffer).str());
643628
}
644629

@@ -649,15 +634,9 @@ void debugger_commands::execute_printf(const std::vector<std::string_view> &para
649634

650635
void debugger_commands::execute_logerror(const std::vector<std::string_view> &params)
651636
{
652-
/* validate the other parameters */
653-
u64 values[MAX_COMMAND_PARAMS];
654-
for (int i = 1; i < params.size(); i++)
655-
if (!m_console.validate_number_parameter(params[i], values[i]))
656-
return;
657-
658637
/* then do a printf */
659638
std::ostringstream buffer;
660-
if (mini_printf(buffer, params[0], params.size() - 1, &values[1]))
639+
if (mini_printf(buffer, params))
661640
m_machine.logerror("%s", std::move(buffer).str());
662641
}
663642

@@ -668,15 +647,9 @@ void debugger_commands::execute_logerror(const std::vector<std::string_view> &pa
668647

669648
void debugger_commands::execute_tracelog(const std::vector<std::string_view> &params)
670649
{
671-
/* validate the other parameters */
672-
u64 values[MAX_COMMAND_PARAMS];
673-
for (int i = 1; i < params.size(); i++)
674-
if (!m_console.validate_number_parameter(params[i], values[i]))
675-
return;
676-
677650
/* then do a printf */
678651
std::ostringstream buffer;
679-
if (mini_printf(buffer, params[0], params.size() - 1, &values[1]))
652+
if (mini_printf(buffer, params))
680653
m_console.get_visible_cpu()->debug()->trace_printf("%s", std::move(buffer).str());
681654
}
682655

@@ -689,7 +662,6 @@ void debugger_commands::execute_tracesym(const std::vector<std::string_view> &pa
689662
{
690663
// build a format string appropriate for the parameters and validate them
691664
std::stringstream format;
692-
u64 values[MAX_COMMAND_PARAMS];
693665
for (int i = 0; i < params.size(); i++)
694666
{
695667
// find this symbol
@@ -704,15 +676,15 @@ void debugger_commands::execute_tracesym(const std::vector<std::string_view> &pa
704676
util::stream_format(format, "%s=%s ",
705677
params[i],
706678
sym->format().empty() ? "%16X" : sym->format());
707-
708-
// validate the parameter
709-
if (!m_console.validate_number_parameter(params[i], values[i]))
710-
return;
711679
}
712680

681+
// build parameters for printf
682+
std::vector<std::string_view> printf_params(params);
683+
printf_params.insert(printf_params.begin(), format.str());
684+
713685
// then do a printf
714686
std::ostringstream buffer;
715-
if (mini_printf(buffer, format.str(), params.size(), values))
687+
if (mini_printf(buffer, printf_params))
716688
m_console.get_visible_cpu()->debug()->trace_printf("%s", std::move(buffer).str());
717689
}
718690

Diff for: src/emu/debug/debugcmd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class debugger_commands
7373
u64 global_get(global_entry *global);
7474
void global_set(global_entry *global, u64 value);
7575

76-
bool mini_printf(std::ostream &stream, std::string_view format, int params, u64 *param);
76+
bool mini_printf(std::ostream &stream, const std::vector<std::string_view> &params);
7777
template <typename T>
7878
void execute_index_command(std::vector<std::string_view> const &params, T &&apply, char const *unused_message);
7979

Diff for: src/emu/debug/debughlp.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,14 @@ const help_item f_static_help_list[] =
359359
"The printf command performs a C-style printf to the debugger console. Only a very limited set of "
360360
"formatting options are available:\n"
361361
"\n"
362-
" %[0][<n>]d -- prints <item> as a decimal value with optional digit count and zero-fill\n"
363-
" %[0][<n>]x -- prints <item> as a hexadecimal value with optional digit count and zero-fill\n"
362+
" %c -- 8-bit character\n"
363+
" %[0][<n>]d -- decimal number with optional digit count and zero-fill\n"
364+
" %[0][<n>]o -- octal number with optional digit count and zero-fill\n"
365+
" %[0][<n>]x -- hexadecimal number with optional digit count and zero-fill (lowercase digits)\n"
366+
" %[0][<n>]X -- hexadecimal number with optional digit count and zero-fill (uppercase digits)\n"
364367
"\n"
365-
"All remaining formatting options are ignored. Use %% together to output a % character. Multiple "
366-
"lines can be printed by embedding a \\n in the text.\n"
368+
"All remaining formatting options are ignored. Use %% to output a % character. Multiple lines can be "
369+
"printed by embedding a \\n in the text.\n"
367370
"\n"
368371
"Examples:\n"
369372
"\n"
@@ -381,11 +384,14 @@ const help_item f_static_help_list[] =
381384
"The logerror command performs a C-style printf to the error log. Only a very limited set of "
382385
"formatting options are available:\n"
383386
"\n"
384-
" %[0][<n>]d -- logs <item> as a decimal value with optional digit count and zero-fill\n"
385-
" %[0][<n>]x -- logs <item> as a hexadecimal value with optional digit count and zero-fill\n"
387+
" %c -- 8-bit character\n"
388+
" %[0][<n>]d -- decimal number with optional digit count and zero-fill\n"
389+
" %[0][<n>]o -- octal number with optional digit count and zero-fill\n"
390+
" %[0][<n>]x -- hexadecimal number with optional digit count and zero-fill (lowercase digits)\n"
391+
" %[0][<n>]X -- hexadecimal number with optional digit count and zero-fill (uppercase digits)\n"
386392
"\n"
387-
"All remaining formatting options are ignored. Use %% together to output a % character. Multiple "
388-
"lines can be printed by embedding a \\n in the text.\n"
393+
"All remaining formatting options are ignored. Use %% to output a % character. Multiple lines can be "
394+
"printed by embedding a \\n in the text.\n"
389395
"\n"
390396
"Examples:\n"
391397
"\n"

0 commit comments

Comments
 (0)