| OLD | NEW |
| 1 /* General python/gdb code | 1 /* General python/gdb code |
| 2 | 2 |
| 3 Copyright (C) 2008-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2008-2012 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GDB. | 5 This file is part of GDB. |
| 6 | 6 |
| 7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "python.h" | 34 #include "python.h" |
| 35 | 35 |
| 36 #include <ctype.h> | 36 #include <ctype.h> |
| 37 | 37 |
| 38 /* Declared constants and enum for python stack printing. */ | 38 /* Declared constants and enum for python stack printing. */ |
| 39 static const char python_excp_none[] = "none"; | 39 static const char python_excp_none[] = "none"; |
| 40 static const char python_excp_full[] = "full"; | 40 static const char python_excp_full[] = "full"; |
| 41 static const char python_excp_message[] = "message"; | 41 static const char python_excp_message[] = "message"; |
| 42 | 42 |
| 43 /* "set python print-stack" choices. */ | 43 /* "set python print-stack" choices. */ |
| 44 static const char *python_excp_enums[] = | 44 static const char *const python_excp_enums[] = |
| 45 { | 45 { |
| 46 python_excp_none, | 46 python_excp_none, |
| 47 python_excp_full, | 47 python_excp_full, |
| 48 python_excp_message, | 48 python_excp_message, |
| 49 NULL | 49 NULL |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 /* The exception printing variable. 'full' if we want to print the | 52 /* The exception printing variable. 'full' if we want to print the |
| 53 error message and stack, 'none' if we want to print nothing, and | 53 error message and stack, 'none' if we want to print nothing, and |
| 54 'message' if we only want to print the error message. 'message' is | 54 'message' if we only want to print the error message. 'message' is |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 python_gdbarch = gdbarch; | 145 python_gdbarch = gdbarch; |
| 146 python_language = language; | 146 python_language = language; |
| 147 | 147 |
| 148 /* Save it and ensure ! PyErr_Occurred () afterwards. */ | 148 /* Save it and ensure ! PyErr_Occurred () afterwards. */ |
| 149 PyErr_Fetch (&env->error_type, &env->error_value, &env->error_traceback); | 149 PyErr_Fetch (&env->error_type, &env->error_value, &env->error_traceback); |
| 150 | 150 |
| 151 return make_cleanup (restore_python_env, env); | 151 return make_cleanup (restore_python_env, env); |
| 152 } | 152 } |
| 153 | 153 |
| 154 /* A wrapper around PyRun_SimpleFile. FILENAME is the name of | 154 /* A wrapper around PyRun_SimpleFile. FILE is the Python script to run |
| 155 the Python script to run. | 155 named FILENAME. |
| 156 | 156 |
| 157 One of the parameters of PyRun_SimpleFile is a FILE *. | 157 On Windows hosts few users would build Python themselves (this is no |
| 158 The problem is that type FILE is extremely system and compiler | 158 trivial task on this platform), and thus use binaries built by |
| 159 dependent. So, unless the Python library has been compiled using | 159 someone else instead. There may happen situation where the Python |
| 160 the same build environment as GDB, we run the risk of getting | 160 library and GDB are using two different versions of the C runtime |
| 161 a crash due to inconsistencies between the definition used by GDB, | 161 library. Python, being built with VC, would use one version of the |
| 162 and the definition used by Python. A mismatch can very likely | 162 msvcr DLL (Eg. msvcr100.dll), while MinGW uses msvcrt.dll. |
| 163 lead to a crash. | 163 A FILE * from one runtime does not necessarily operate correctly in |
| 164 | |
| 165 There is also the situation where the Python library and GDB | |
| 166 are using two different versions of the C runtime library. | |
| 167 This is particularly visible on Windows, where few users would | |
| 168 build Python themselves (this is no trivial task on this platform), | |
| 169 and thus use binaries built by someone else instead. Python, | |
| 170 being built with VC, would use one version of the msvcr DLL | |
| 171 (Eg. msvcr100.dll), while MinGW uses msvcrt.dll. A FILE * | |
| 172 from one runtime does not necessarily operate correctly in | |
| 173 the other runtime. | 164 the other runtime. |
| 174 | 165 |
| 175 To work around this potential issue, we create the FILE object | 166 To work around this potential issue, we create on Windows hosts the |
| 176 using Python routines, thus making sure that it is compatible | 167 FILE object using Python routines, thus making sure that it is |
| 177 with the Python library. */ | 168 compatible with the Python library. */ |
| 178 | 169 |
| 179 static void | 170 static void |
| 180 python_run_simple_file (const char *filename) | 171 python_run_simple_file (FILE *file, const char *filename) |
| 181 { | 172 { |
| 173 #ifndef _WIN32 |
| 174 |
| 175 PyRun_SimpleFile (file, filename); |
| 176 |
| 177 #else /* _WIN32 */ |
| 178 |
| 182 char *full_path; | 179 char *full_path; |
| 183 PyObject *python_file; | 180 PyObject *python_file; |
| 184 struct cleanup *cleanup; | 181 struct cleanup *cleanup; |
| 185 | 182 |
| 186 /* Because we have a string for a filename, and are using Python to | 183 /* Because we have a string for a filename, and are using Python to |
| 187 open the file, we need to expand any tilde in the path first. */ | 184 open the file, we need to expand any tilde in the path first. */ |
| 188 full_path = tilde_expand (filename); | 185 full_path = tilde_expand (filename); |
| 189 cleanup = make_cleanup (xfree, full_path); | 186 cleanup = make_cleanup (xfree, full_path); |
| 190 python_file = PyFile_FromString (full_path, "r"); | 187 python_file = PyFile_FromString (full_path, "r"); |
| 191 if (! python_file) | 188 if (! python_file) |
| 192 { | 189 { |
| 193 do_cleanups (cleanup); | 190 do_cleanups (cleanup); |
| 194 gdbpy_print_stack (); | 191 gdbpy_print_stack (); |
| 195 error (_("Error while opening file: %s"), full_path); | 192 error (_("Error while opening file: %s"), full_path); |
| 196 } | 193 } |
| 197 | 194 |
| 198 make_cleanup_py_decref (python_file); | 195 make_cleanup_py_decref (python_file); |
| 199 PyRun_SimpleFile (PyFile_AsFile (python_file), filename); | 196 PyRun_SimpleFile (PyFile_AsFile (python_file), filename); |
| 200 do_cleanups (cleanup); | 197 do_cleanups (cleanup); |
| 198 |
| 199 #endif /* _WIN32 */ |
| 201 } | 200 } |
| 202 | 201 |
| 203 /* Given a command_line, return a command string suitable for passing | 202 /* Given a command_line, return a command string suitable for passing |
| 204 to Python. Lines in the string are separated by newlines. The | 203 to Python. Lines in the string are separated by newlines. The |
| 205 return value is allocated using xmalloc and the caller is | 204 return value is allocated using xmalloc and the caller is |
| 206 responsible for freeing it. */ | 205 responsible for freeing it. */ |
| 207 | 206 |
| 208 static char * | 207 static char * |
| 209 compute_python_string (struct command_line *l) | 208 compute_python_string (struct command_line *l) |
| 210 { | 209 { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 } | 493 } |
| 495 | 494 |
| 496 return str_obj; | 495 return str_obj; |
| 497 } | 496 } |
| 498 | 497 |
| 499 /* A Python function which is a wrapper for decode_line_1. */ | 498 /* A Python function which is a wrapper for decode_line_1. */ |
| 500 | 499 |
| 501 static PyObject * | 500 static PyObject * |
| 502 gdbpy_decode_line (PyObject *self, PyObject *args) | 501 gdbpy_decode_line (PyObject *self, PyObject *args) |
| 503 { | 502 { |
error: old chunk mismatch |
None
| OLD | NEW |