gdb/gdbserver/debug.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Debugging routines for the remote server for GDB.
  2.    Copyright (C) 2014-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "server.h"
  15. #include <sys/time.h>

  16. /* Enable miscellaneous debugging output.  The name is historical - it
  17.    was originally used to debug LinuxThreads support.  */
  18. int debug_threads;

  19. /* Include timestamps in debugging output.  */
  20. int debug_timestamp;

  21. /* Print a debugging message.
  22.    If the text begins a new line it is preceded by a timestamp, if the
  23.    system has gettimeofday.
  24.    We don't get fancy with newline checking, we just check whether the
  25.    previous call ended with "\n".  */

  26. void
  27. debug_vprintf (const char *format, va_list ap)
  28. {
  29. #if !defined (IN_PROCESS_AGENT)
  30.   /* N.B. Not thread safe, and can't be used, as is, with IPA.  */
  31.   static int new_line = 1;

  32.   if (debug_timestamp && new_line)
  33.     {
  34.       struct timeval tm;

  35.       gettimeofday (&tm, NULL);

  36.       /* If gettimeofday doesn't exist, and as a portability solution it has
  37.          been replaced with, e.g., time, then it doesn't make sense to print
  38.          the microseconds field.  Is there a way to check for that?  */
  39.       fprintf (stderr, "%ld:%06ld ", (long) tm.tv_sec, (long) tm.tv_usec);
  40.     }
  41. #endif

  42.   vfprintf (stderr, format, ap);

  43. #if !defined (IN_PROCESS_AGENT)
  44.   if (*format)
  45.     new_line = format[strlen (format) - 1] == '\n';
  46. #endif
  47. }

  48. /* Flush debugging output.
  49.    This is called, for example, when starting an inferior to ensure all debug
  50.    output thus far appears before any inferior output.  */

  51. void
  52. debug_flush (void)
  53. {
  54.   fflush (stderr);
  55. }

  56. /* Notify the user that the code is entering FUNCTION_NAME.
  57.    FUNCTION_NAME is the name of the calling function, or NULL if unknown.

  58.    This is intended to be called via the debug_enter macro.  */

  59. void
  60. do_debug_enter (const char *function_name)
  61. {
  62.   if (function_name != NULL)
  63.     debug_printf (">>>> entering %s\n", function_name);
  64. }

  65. /* Notify the user that the code is exiting FUNCTION_NAME.
  66.    FUNCTION_NAME is the name of the calling function, or NULL if unknown.

  67.    This is intended to be called via the debug_exit macro.  */

  68. void
  69. do_debug_exit (const char *function_name)
  70. {
  71.   if (function_name != NULL)
  72.     debug_printf ("<<<< exiting %s\n", function_name);
  73. }