OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.2/] [gdb/] [python/] [python.c] - Blame information for rev 330

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
/* General python/gdb code
2
 
3
   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
 
20
#include "defs.h"
21
#include "arch-utils.h"
22
#include "command.h"
23
#include "ui-out.h"
24
#include "cli/cli-script.h"
25
#include "gdbcmd.h"
26
#include "progspace.h"
27
#include "objfiles.h"
28
#include "value.h"
29
#include "language.h"
30
#include "exceptions.h"
31
 
32
#include <ctype.h>
33
 
34
/* True if we should print the stack when catching a Python error,
35
   false otherwise.  */
36
static int gdbpy_should_print_stack = 1;
37
 
38
#ifdef HAVE_PYTHON
39
 
40
#include "python.h"
41
#include "libiberty.h"
42
#include "cli/cli-decode.h"
43
#include "charset.h"
44
#include "top.h"
45
#include "python-internal.h"
46
#include "version.h"
47
#include "target.h"
48
#include "gdbthread.h"
49
 
50
static PyMethodDef GdbMethods[];
51
 
52
PyObject *gdb_module;
53
 
54
/* Some string constants we may wish to use.  */
55
PyObject *gdbpy_to_string_cst;
56
PyObject *gdbpy_children_cst;
57
PyObject *gdbpy_display_hint_cst;
58
PyObject *gdbpy_doc_cst;
59
PyObject *gdbpy_enabled_cst;
60
 
61
/* The GdbError exception.  */
62
PyObject *gdbpy_gdberror_exc;
63
 
64
/* Architecture and language to be used in callbacks from
65
   the Python interpreter.  */
66
struct gdbarch *python_gdbarch;
67
const struct language_defn *python_language;
68
 
69
/* Restore global language and architecture and Python GIL state
70
   when leaving the Python interpreter.  */
71
 
72
struct python_env
73
{
74
  PyGILState_STATE state;
75
  struct gdbarch *gdbarch;
76
  const struct language_defn *language;
77
};
78
 
79
static void
80
restore_python_env (void *p)
81
{
82
  struct python_env *env = (struct python_env *)p;
83
 
84
  PyGILState_Release (env->state);
85
  python_gdbarch = env->gdbarch;
86
  python_language = env->language;
87
  xfree (env);
88
}
89
 
90
/* Called before entering the Python interpreter to install the
91
   current language and architecture to be used for Python values.  */
92
 
93
struct cleanup *
94
ensure_python_env (struct gdbarch *gdbarch,
95
                   const struct language_defn *language)
96
{
97
  struct python_env *env = xmalloc (sizeof *env);
98
 
99
  env->state = PyGILState_Ensure ();
100
  env->gdbarch = python_gdbarch;
101
  env->language = python_language;
102
 
103
  python_gdbarch = gdbarch;
104
  python_language = language;
105
 
106
  return make_cleanup (restore_python_env, env);
107
}
108
 
109
 
110
/* Given a command_line, return a command string suitable for passing
111
   to Python.  Lines in the string are separated by newlines.  The
112
   return value is allocated using xmalloc and the caller is
113
   responsible for freeing it.  */
114
 
115
static char *
116
compute_python_string (struct command_line *l)
117
{
118
  struct command_line *iter;
119
  char *script = NULL;
120
  int size = 0;
121
  int here;
122
 
123
  for (iter = l; iter; iter = iter->next)
124
    size += strlen (iter->line) + 1;
125
 
126
  script = xmalloc (size + 1);
127
  here = 0;
128
  for (iter = l; iter; iter = iter->next)
129
    {
130
      int len = strlen (iter->line);
131
 
132
      strcpy (&script[here], iter->line);
133
      here += len;
134
      script[here++] = '\n';
135
    }
136
  script[here] = '\0';
137
  return script;
138
}
139
 
140
/* Take a command line structure representing a 'python' command, and
141
   evaluate its body using the Python interpreter.  */
142
 
143
void
144
eval_python_from_control_command (struct command_line *cmd)
145
{
146
  int ret;
147
  char *script;
148
  struct cleanup *cleanup;
149
 
150
  if (cmd->body_count != 1)
151
    error (_("Invalid \"python\" block structure."));
152
 
153
  cleanup = ensure_python_env (get_current_arch (), current_language);
154
 
155
  script = compute_python_string (cmd->body_list[0]);
156
  ret = PyRun_SimpleString (script);
157
  xfree (script);
158
  if (ret)
159
    {
160
      gdbpy_print_stack ();
161
      error (_("Error while executing Python code."));
162
    }
163
 
164
  do_cleanups (cleanup);
165
}
166
 
167
/* Implementation of the gdb "python" command.  */
168
 
169
static void
170
python_command (char *arg, int from_tty)
171
{
172
  struct cleanup *cleanup;
173
 
174
  cleanup = ensure_python_env (get_current_arch (), current_language);
175
  while (arg && *arg && isspace (*arg))
176
    ++arg;
177
  if (arg && *arg)
178
    {
179
      if (PyRun_SimpleString (arg))
180
        {
181
          gdbpy_print_stack ();
182
          error (_("Error while executing Python code."));
183
        }
184
    }
185
  else
186
    {
187
      struct command_line *l = get_command_line (python_control, "");
188
 
189
      make_cleanup_free_command_lines (&l);
190
      execute_control_command_untraced (l);
191
    }
192
 
193
  do_cleanups (cleanup);
194
}
195
 
196
 
197
 
198
/* Transform a gdb parameters's value into a Python value.  May return
199
   NULL (and set a Python exception) on error.  Helper function for
200
   get_parameter.  */
201
PyObject *
202
gdbpy_parameter_value (enum var_types type, void *var)
203
{
204
  switch (type)
205
    {
206
    case var_string:
207
    case var_string_noescape:
208
    case var_optional_filename:
209
    case var_filename:
210
    case var_enum:
211
      {
212
        char *str = * (char **) var;
213
 
214
        if (! str)
215
          str = "";
216
        return PyString_Decode (str, strlen (str), host_charset (), NULL);
217
      }
218
 
219
    case var_boolean:
220
      {
221
        if (* (int *) var)
222
          Py_RETURN_TRUE;
223
        else
224
          Py_RETURN_FALSE;
225
      }
226
 
227
    case var_auto_boolean:
228
      {
229
        enum auto_boolean ab = * (enum auto_boolean *) var;
230
 
231
        if (ab == AUTO_BOOLEAN_TRUE)
232
          Py_RETURN_TRUE;
233
        else if (ab == AUTO_BOOLEAN_FALSE)
234
          Py_RETURN_FALSE;
235
        else
236
          Py_RETURN_NONE;
237
      }
238
 
239
    case var_integer:
240
      if ((* (int *) var) == INT_MAX)
241
        Py_RETURN_NONE;
242
      /* Fall through.  */
243
    case var_zinteger:
244
      return PyLong_FromLong (* (int *) var);
245
 
246
    case var_uinteger:
247
      {
248
        unsigned int val = * (unsigned int *) var;
249
 
250
        if (val == UINT_MAX)
251
          Py_RETURN_NONE;
252
        return PyLong_FromUnsignedLong (val);
253
      }
254
    }
255
 
256
  return PyErr_Format (PyExc_RuntimeError,
257
                       _("Programmer error: unhandled type."));
258
}
259
 
260
/* A Python function which returns a gdb parameter's value as a Python
261
   value.  */
262
 
263
PyObject *
264
gdbpy_parameter (PyObject *self, PyObject *args)
265
{
266
  struct cmd_list_element *alias, *prefix, *cmd;
267
  char *arg, *newarg;
268
  int found = -1;
269
  volatile struct gdb_exception except;
270
 
271
  if (! PyArg_ParseTuple (args, "s", &arg))
272
    return NULL;
273
 
274
  newarg = concat ("show ", arg, (char *) NULL);
275
 
276
  TRY_CATCH (except, RETURN_MASK_ALL)
277
    {
278
      found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
279
    }
280
  xfree (newarg);
281
  GDB_PY_HANDLE_EXCEPTION (except);
282
  if (!found)
283
    return PyErr_Format (PyExc_RuntimeError,
284
                         _("Could not find parameter `%s'."), arg);
285
 
286
  if (! cmd->var)
287
    return PyErr_Format (PyExc_RuntimeError,
288
                         _("`%s' is not a parameter."), arg);
289
  return gdbpy_parameter_value (cmd->var_type, cmd->var);
290
}
291
 
292
/* Wrapper for target_charset.  */
293
 
294
static PyObject *
295
gdbpy_target_charset (PyObject *self, PyObject *args)
296
{
297
  const char *cset = target_charset (python_gdbarch);
298
 
299
  return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
300
}
301
 
302
/* Wrapper for target_wide_charset.  */
303
 
304
static PyObject *
305
gdbpy_target_wide_charset (PyObject *self, PyObject *args)
306
{
307
  const char *cset = target_wide_charset (python_gdbarch);
308
 
309
  return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL);
310
}
311
 
312
/* A Python function which evaluates a string using the gdb CLI.  */
313
 
314
static PyObject *
315
execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
316
{
317
  char *arg;
318
  PyObject *from_tty_obj = NULL, *to_string_obj = NULL;
319
  int from_tty, to_string;
320
  volatile struct gdb_exception except;
321
  static char *keywords[] = {"command", "from_tty", "to_string", NULL };
322
  char *result = NULL;
323
 
324
  if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg,
325
                                     &PyBool_Type, &from_tty_obj,
326
                                     &PyBool_Type, &to_string_obj))
327
    return NULL;
328
 
329
  from_tty = 0;
330
  if (from_tty_obj)
331
    {
332
      int cmp = PyObject_IsTrue (from_tty_obj);
333
      if (cmp < 0)
334
        return NULL;
335
      from_tty = cmp;
336
    }
337
 
338
  to_string = 0;
339
  if (to_string_obj)
340
    {
341
      int cmp = PyObject_IsTrue (to_string_obj);
342
      if (cmp < 0)
343
        return NULL;
344
      to_string = cmp;
345
    }
346
 
347
  TRY_CATCH (except, RETURN_MASK_ALL)
348
    {
349
      /* Copy the argument text in case the command modifies it.  */
350
      char *copy = xstrdup (arg);
351
      struct cleanup *cleanup = make_cleanup (xfree, copy);
352
 
353
      if (to_string)
354
        result = execute_command_to_string (copy, from_tty);
355
      else
356
        {
357
          result = NULL;
358
          execute_command (copy, from_tty);
359
        }
360
 
361
      do_cleanups (cleanup);
362
    }
363
  GDB_PY_HANDLE_EXCEPTION (except);
364
 
365
  /* Do any commands attached to breakpoint we stopped at.  */
366
  bpstat_do_actions ();
367
 
368
  if (result)
369
    {
370
      PyObject *r = PyString_FromString (result);
371
      xfree (result);
372
      return r;
373
    }
374
  Py_RETURN_NONE;
375
}
376
 
377
/* Parse a string and evaluate it as an expression.  */
378
static PyObject *
379
gdbpy_parse_and_eval (PyObject *self, PyObject *args)
380
{
381
  char *expr_str;
382
  struct value *result = NULL;
383
  volatile struct gdb_exception except;
384
 
385
  if (!PyArg_ParseTuple (args, "s", &expr_str))
386
    return NULL;
387
 
388
  TRY_CATCH (except, RETURN_MASK_ALL)
389
    {
390
      result = parse_and_eval (expr_str);
391
    }
392
  GDB_PY_HANDLE_EXCEPTION (except);
393
 
394
  return value_to_value_object (result);
395
}
396
 
397
/* Read a file as Python code.  STREAM is the input file; FILE is the
398
   name of the file.
399
   STREAM is not closed, that is the caller's responsibility.  */
400
 
401
void
402
source_python_script (FILE *stream, const char *file)
403
{
404
  struct cleanup *cleanup;
405
 
406
  cleanup = ensure_python_env (get_current_arch (), current_language);
407
 
408
  /* Note: If an exception occurs python will print the traceback and
409
     clear the error indicator.  */
410
  PyRun_SimpleFile (stream, file);
411
 
412
  do_cleanups (cleanup);
413
}
414
 
415
 
416
 
417
/* Printing.  */
418
 
419
/* A python function to write a single string using gdb's filtered
420
   output stream.  */
421
static PyObject *
422
gdbpy_write (PyObject *self, PyObject *args)
423
{
424
  char *arg;
425
 
426
  if (! PyArg_ParseTuple (args, "s", &arg))
427
    return NULL;
428
  printf_filtered ("%s", arg);
429
  Py_RETURN_NONE;
430
}
431
 
432
/* A python function to flush gdb's filtered output stream.  */
433
static PyObject *
434
gdbpy_flush (PyObject *self, PyObject *args)
435
{
436
  gdb_flush (gdb_stdout);
437
  Py_RETURN_NONE;
438
}
439
 
440
/* Print a python exception trace, or print nothing and clear the
441
   python exception, depending on gdbpy_should_print_stack.  Only call
442
   this if a python exception is set.  */
443
void
444
gdbpy_print_stack (void)
445
{
446
  if (gdbpy_should_print_stack)
447
    {
448
      PyErr_Print ();
449
      /* PyErr_Print doesn't necessarily end output with a newline.
450
         This works because Python's stdout/stderr is fed through
451
         printf_filtered.  */
452
      begin_line ();
453
    }
454
  else
455
    PyErr_Clear ();
456
}
457
 
458
 
459
 
460
/* Return the current Progspace.
461
   There always is one.  */
462
 
463
static PyObject *
464
gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
465
{
466
  PyObject *result;
467
 
468
  result = pspace_to_pspace_object (current_program_space);
469
  if (result)
470
    Py_INCREF (result);
471
  return result;
472
}
473
 
474
/* Return a sequence holding all the Progspaces.  */
475
 
476
static PyObject *
477
gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
478
{
479
  struct program_space *ps;
480
  PyObject *list;
481
 
482
  list = PyList_New (0);
483
  if (!list)
484
    return NULL;
485
 
486
  ALL_PSPACES (ps)
487
  {
488
    PyObject *item = pspace_to_pspace_object (ps);
489
 
490
    if (!item || PyList_Append (list, item) == -1)
491
      {
492
        Py_DECREF (list);
493
        return NULL;
494
      }
495
  }
496
 
497
  return list;
498
}
499
 
500
 
501
 
502
/* The "current" objfile.  This is set when gdb detects that a new
503
   objfile has been loaded.  It is only set for the duration of a call to
504
   source_python_script_for_objfile; it is NULL at other times.  */
505
static struct objfile *gdbpy_current_objfile;
506
 
507
/* Set the current objfile to OBJFILE and then read STREAM,FILE as
508
   Python code.  */
509
 
510
void
511
source_python_script_for_objfile (struct objfile *objfile,
512
                                  FILE *stream, const char *file)
513
{
514
  struct cleanup *cleanups;
515
 
516
  cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
517
  gdbpy_current_objfile = objfile;
518
 
519
  /* Note: If an exception occurs python will print the traceback and
520
     clear the error indicator.  */
521
  PyRun_SimpleFile (stream, file);
522
 
523
  do_cleanups (cleanups);
524
  gdbpy_current_objfile = NULL;
525
}
526
 
527
/* Return the current Objfile, or None if there isn't one.  */
528
 
529
static PyObject *
530
gdbpy_get_current_objfile (PyObject *unused1, PyObject *unused2)
531
{
532
  PyObject *result;
533
 
534
  if (! gdbpy_current_objfile)
535
    Py_RETURN_NONE;
536
 
537
  result = objfile_to_objfile_object (gdbpy_current_objfile);
538
  if (result)
539
    Py_INCREF (result);
540
  return result;
541
}
542
 
543
/* Return a sequence holding all the Objfiles.  */
544
 
545
static PyObject *
546
gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
547
{
548
  struct objfile *objf;
549
  PyObject *list;
550
 
551
  list = PyList_New (0);
552
  if (!list)
553
    return NULL;
554
 
555
  ALL_OBJFILES (objf)
556
  {
557
    PyObject *item = objfile_to_objfile_object (objf);
558
 
559
    if (!item || PyList_Append (list, item) == -1)
560
      {
561
        Py_DECREF (list);
562
        return NULL;
563
      }
564
  }
565
 
566
  return list;
567
}
568
 
569
#else /* HAVE_PYTHON */
570
 
571
/* Dummy implementation of the gdb "python" command.  */
572
 
573
static void
574
python_command (char *arg, int from_tty)
575
{
576
  while (arg && *arg && isspace (*arg))
577
    ++arg;
578
  if (arg && *arg)
579
    error (_("Python scripting is not supported in this copy of GDB."));
580
  else
581
    {
582
      struct command_line *l = get_command_line (python_control, "");
583
      struct cleanup *cleanups = make_cleanup_free_command_lines (&l);
584
 
585
      execute_control_command_untraced (l);
586
      do_cleanups (cleanups);
587
    }
588
}
589
 
590
void
591
eval_python_from_control_command (struct command_line *cmd)
592
{
593
  error (_("Python scripting is not supported in this copy of GDB."));
594
}
595
 
596
void
597
source_python_script (FILE *stream, const char *file)
598
{
599
  throw_error (UNSUPPORTED_ERROR,
600
               _("Python scripting is not supported in this copy of GDB."));
601
}
602
 
603
#endif /* HAVE_PYTHON */
604
 
605
 
606
 
607
/* Lists for 'maint set python' commands.  */
608
 
609
struct cmd_list_element *set_python_list;
610
struct cmd_list_element *show_python_list;
611
 
612
/* Function for use by 'maint set python' prefix command.  */
613
 
614
static void
615
set_python (char *args, int from_tty)
616
{
617
  help_list (set_python_list, "maintenance set python ", -1, gdb_stdout);
618
}
619
 
620
/* Function for use by 'maint show python' prefix command.  */
621
 
622
static void
623
show_python (char *args, int from_tty)
624
{
625
  cmd_show_list (show_python_list, from_tty, "");
626
}
627
 
628
/* Initialize the Python code.  */
629
 
630
/* Provide a prototype to silence -Wmissing-prototypes.  */
631
extern initialize_file_ftype _initialize_python;
632
 
633
void
634
_initialize_python (void)
635
{
636
  add_com ("python", class_obscure, python_command,
637
#ifdef HAVE_PYTHON
638
           _("\
639
Evaluate a Python command.\n\
640
\n\
641
The command can be given as an argument, for instance:\n\
642
\n\
643
    python print 23\n\
644
\n\
645
If no argument is given, the following lines are read and used\n\
646
as the Python commands.  Type a line containing \"end\" to indicate\n\
647
the end of the command.")
648
#else /* HAVE_PYTHON */
649
           _("\
650
Evaluate a Python command.\n\
651
\n\
652
Python scripting is not supported in this copy of GDB.\n\
653
This command is only a placeholder.")
654
#endif /* HAVE_PYTHON */
655
           );
656
 
657
  add_prefix_cmd ("python", no_class, show_python,
658
                  _("Prefix command for python maintenance settings."),
659
                  &show_python_list, "maintenance show python ", 0,
660
                  &maintenance_show_cmdlist);
661
  add_prefix_cmd ("python", no_class, set_python,
662
                  _("Prefix command for python maintenance settings."),
663
                  &set_python_list, "maintenance set python ", 0,
664
                  &maintenance_set_cmdlist);
665
 
666
  add_setshow_boolean_cmd ("print-stack", class_maintenance,
667
                           &gdbpy_should_print_stack, _("\
668
Enable or disable printing of Python stack dump on error."), _("\
669
Show whether Python stack will be printed on error."), _("\
670
Enables or disables printing of Python stack traces."),
671
                           NULL, NULL,
672
                           &set_python_list,
673
                           &show_python_list);
674
 
675
#ifdef HAVE_PYTHON
676
#ifdef WITH_PYTHON_PATH
677
  /* Work around problem where python gets confused about where it is,
678
     and then can't find its libraries, etc.
679
     NOTE: Python assumes the following layout:
680
     /foo/bin/python
681
     /foo/lib/pythonX.Y/...
682
     This must be done before calling Py_Initialize.  */
683
  Py_SetProgramName (concat (ldirname (python_libdir), SLASH_STRING, "bin",
684
                             SLASH_STRING, "python", NULL));
685
#endif
686
 
687
  Py_Initialize ();
688
  PyEval_InitThreads ();
689
 
690
  gdb_module = Py_InitModule ("gdb", GdbMethods);
691
 
692
  /* The casts to (char*) are for python 2.4.  */
693
  PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
694
  PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
695
  PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name);
696
  {
697
    char *gdb_pythondir;
698
 
699
    gdb_pythondir = concat (gdb_datadir, SLASH_STRING, "python", NULL);
700
    PyModule_AddStringConstant (gdb_module, "PYTHONDIR", gdb_pythondir);
701
    xfree (gdb_pythondir);
702
  }
703
 
704
  gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
705
  PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc);
706
 
707
  gdbpy_initialize_auto_load ();
708
  gdbpy_initialize_values ();
709
  gdbpy_initialize_frames ();
710
  gdbpy_initialize_commands ();
711
  gdbpy_initialize_symbols ();
712
  gdbpy_initialize_symtabs ();
713
  gdbpy_initialize_blocks ();
714
  gdbpy_initialize_functions ();
715
  gdbpy_initialize_parameters ();
716
  gdbpy_initialize_types ();
717
  gdbpy_initialize_pspace ();
718
  gdbpy_initialize_objfile ();
719
  gdbpy_initialize_breakpoints ();
720
  gdbpy_initialize_lazy_string ();
721
  gdbpy_initialize_thread ();
722
  gdbpy_initialize_inferior ();
723
 
724
  PyRun_SimpleString ("import gdb");
725
  PyRun_SimpleString ("gdb.pretty_printers = []");
726
 
727
  gdbpy_to_string_cst = PyString_FromString ("to_string");
728
  gdbpy_children_cst = PyString_FromString ("children");
729
  gdbpy_display_hint_cst = PyString_FromString ("display_hint");
730
  gdbpy_doc_cst = PyString_FromString ("__doc__");
731
  gdbpy_enabled_cst = PyString_FromString ("enabled");
732
 
733
  /* Create a couple objects which are used for Python's stdout and
734
     stderr.  */
735
  PyRun_SimpleString ("\
736
import sys\n\
737
class GdbOutputFile:\n\
738
  def close(self):\n\
739
    # Do nothing.\n\
740
    return None\n\
741
\n\
742
  def isatty(self):\n\
743
    return False\n\
744
\n\
745
  def write(self, s):\n\
746
    gdb.write(s)\n\
747
\n\
748
  def writelines(self, iterable):\n\
749
    for line in iterable:\n\
750
      self.write(line)\n\
751
\n\
752
  def flush(self):\n\
753
    gdb.flush()\n\
754
\n\
755
sys.stderr = GdbOutputFile()\n\
756
sys.stdout = GdbOutputFile()\n\
757
\n\
758
# GDB's python scripts are stored inside gdb.PYTHONDIR.  So insert\n\
759
# that directory name at the start of sys.path to allow the Python\n\
760
# interpreter to find them.\n\
761
sys.path.insert(0, gdb.PYTHONDIR)\n\
762
\n\
763
# The gdb module is implemented in C rather than in Python.  As a result,\n\
764
# the associated __init.py__ script is not not executed by default when\n\
765
# the gdb module gets imported.  Execute that script manually if it exists.\n\
766
gdb.__path__ = [gdb.PYTHONDIR + '/gdb']\n\
767
from os.path import exists\n\
768
ipy = gdb.PYTHONDIR + '/gdb/__init__.py'\n\
769
if exists (ipy):\n\
770
  execfile (ipy)\n\
771
");
772
 
773
  /* Release the GIL while gdb runs.  */
774
  PyThreadState_Swap (NULL);
775
  PyEval_ReleaseLock ();
776
 
777
#endif /* HAVE_PYTHON */
778
}
779
 
780
 
781
 
782
#if HAVE_PYTHON
783
 
784
static PyMethodDef GdbMethods[] =
785
{
786
  { "history", gdbpy_history, METH_VARARGS,
787
    "Get a value from history" },
788
  { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
789
    "Execute a gdb command" },
790
  { "parameter", gdbpy_parameter, METH_VARARGS,
791
    "Return a gdb parameter's value" },
792
 
793
  { "breakpoints", gdbpy_breakpoints, METH_NOARGS,
794
    "Return a tuple of all breakpoint objects" },
795
 
796
  { "default_visualizer", gdbpy_default_visualizer, METH_VARARGS,
797
    "Find the default visualizer for a Value." },
798
 
799
  { "current_progspace", gdbpy_get_current_progspace, METH_NOARGS,
800
    "Return the current Progspace." },
801
  { "progspaces", gdbpy_progspaces, METH_NOARGS,
802
    "Return a sequence of all progspaces." },
803
 
804
  { "current_objfile", gdbpy_get_current_objfile, METH_NOARGS,
805
    "Return the current Objfile being loaded, or None." },
806
  { "objfiles", gdbpy_objfiles, METH_NOARGS,
807
    "Return a sequence of all loaded objfiles." },
808
 
809
  { "selected_frame", gdbpy_selected_frame, METH_NOARGS,
810
    "selected_frame () -> gdb.Frame.\n\
811
Return the selected frame object." },
812
  { "frame_stop_reason_string", gdbpy_frame_stop_reason_string, METH_VARARGS,
813
    "stop_reason_string (Integer) -> String.\n\
814
Return a string explaining unwind stop reason." },
815
 
816
  { "lookup_type", (PyCFunction) gdbpy_lookup_type,
817
    METH_VARARGS | METH_KEYWORDS,
818
    "lookup_type (name [, block]) -> type\n\
819
Return a Type corresponding to the given name." },
820
  { "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
821
    METH_VARARGS | METH_KEYWORDS,
822
    "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
823
Return a tuple with the symbol corresponding to the given name (or None) and\n\
824
a boolean indicating if name is a field of the current implied argument\n\
825
`this' (when the current language is object-oriented)." },
826
  { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
827
    "Return the block containing the given pc value, or None." },
828
  { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
829
    "parse_and_eval (String) -> Value.\n\
830
Parse String as an expression, evaluate it, and return the result as a Value."
831
  },
832
 
833
  { "target_charset", gdbpy_target_charset, METH_NOARGS,
834
    "target_charset () -> string.\n\
835
Return the name of the current target charset." },
836
  { "target_wide_charset", gdbpy_target_wide_charset, METH_NOARGS,
837
    "target_wide_charset () -> string.\n\
838
Return the name of the current target wide charset." },
839
 
840
  { "string_to_argv", gdbpy_string_to_argv, METH_VARARGS,
841
    "string_to_argv (String) -> Array.\n\
842
Parse String and return an argv-like array.\n\
843
Arguments are separate by spaces and may be quoted."
844
  },
845
 
846
  { "write", gdbpy_write, METH_VARARGS,
847
    "Write a string using gdb's filtered stream." },
848
  { "flush", gdbpy_flush, METH_NOARGS,
849
    "Flush gdb's filtered stdout stream." },
850
  { "selected_thread", gdbpy_selected_thread, METH_NOARGS,
851
    "selected_thread () -> gdb.InferiorThread.\n\
852
Return the selected thread object." },
853
  { "inferiors", gdbpy_inferiors, METH_NOARGS,
854
    "inferiors () -> (gdb.Inferior, ...).\n\
855
Return a tuple containing all inferiors." },
856
  {NULL, NULL, 0, NULL}
857
};
858
 
859
#endif /* HAVE_PYTHON */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.