[PATCH] gdb: add linux_nat_debug_printf macro

Simon Marchi simark@simark.ca
Fri Jul 10 13:55:40 GMT 2020


On 2020-07-10 7:47 a.m., Gary Benson via Gdb-patches wrote:
> Simon Marchi wrote:
>> diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
>> index fde360f5080a..3b5c803b83fd 100644
>> --- a/gdb/linux-nat.c
>> +++ b/gdb/linux-nat.c
>> @@ -198,6 +198,27 @@ show_debug_linux_nat (struct ui_file *file, int from_tty,
>>  		    value);
>>  }
>>
>> +/* Print a debug statement.  Should be used through linux_nat_debug_printf.  */
>> +
>> +static void ATTRIBUTE_PRINTF (2, 3)
>> +linux_nat_debug_printf_1 (const char *func_name, const char *fmt, ...)
>> +{
>> +  fprintf_unfiltered (gdb_stdlog, "[linux-nat] %s: ", func_name);
>> +
>> +  va_list ap;
>> +  va_start (ap, fmt);
>> +  vfprintf_unfiltered (gdb_stdlog, fmt, ap);
>> +  va_end (ap);
>> +
>> +  fprintf_unfiltered (gdb_stdlog, "\n");
>> +}
> 
> Would it be useful to use debug_printf and debug_vprintf here?
> 
> Thanks,
> Gary

Indeed, I think the result would be the same, and it seems to exist for this purpose.  I've
replaced locally the implementation of linux_nat_debug_printf_1 with:

static void ATTRIBUTE_PRINTF (2, 3)
linux_nat_debug_printf_1 (const char *func_name, const char *fmt, ...)
{
  debug_printf ("[linux-nat] %s: ", func_name);

  va_list ap;
  va_start (ap, fmt);
  debug_vprintf (fmt, ap);
  va_end (ap);

  debug_printf ("\n");
}

Simon


More information about the Gdb-patches mailing list