tgt_module.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Wine debugger - loading a module for debug purposes
  3. *
  4. * Copyright 2006 Eric Pouech
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <stdarg.h>
  24. #include "debugger.h"
  25. static struct be_process_io be_process_module_io;
  26. static BOOL tgt_process_module_read(HANDLE hProcess, const void* addr,
  27. void* buffer, SIZE_T len, SIZE_T* rlen)
  28. {
  29. return FALSE;
  30. }
  31. static BOOL tgt_process_module_write(HANDLE hProcess, void* addr,
  32. const void* buffer, SIZE_T len, SIZE_T* wlen)
  33. {
  34. return FALSE;
  35. }
  36. enum dbg_start tgt_module_load(const char* name, BOOL keep)
  37. {
  38. DWORD opts = SymGetOptions();
  39. BOOL native;
  40. HANDLE hDummy = (HANDLE)0x87654321;
  41. enum dbg_start ret = start_ok;
  42. WCHAR* nameW;
  43. unsigned len;
  44. SymSetOptions((opts & ~(SYMOPT_UNDNAME|SYMOPT_DEFERRED_LOADS)) |
  45. SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS);
  46. native = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
  47. if (!dbg_init(hDummy, NULL, FALSE))
  48. return start_error_init;
  49. len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
  50. nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
  51. if (!nameW)
  52. {
  53. ret = start_error_init;
  54. keep = FALSE;
  55. }
  56. else
  57. {
  58. len = MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, len);
  59. if (!dbg_load_module(hDummy, NULL, nameW, 0, 0))
  60. {
  61. ret = start_error_init;
  62. keep = FALSE;
  63. }
  64. HeapFree(GetProcessHeap(), 0, nameW);
  65. }
  66. if (keep)
  67. {
  68. dbg_printf("Non supported mode... errors may occur\n"
  69. "Use at your own risks\n");
  70. SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
  71. dbg_curr_process = dbg_add_process(&be_process_module_io, 1, hDummy);
  72. dbg_curr_pid = 1;
  73. dbg_curr_thread = dbg_add_thread(dbg_curr_process, 2, NULL, NULL);
  74. /* FIXME: missing thread creation, fetching frames, restoring dbghelp's options... */
  75. }
  76. else
  77. {
  78. SymCleanup(hDummy);
  79. SymSetOptions(opts);
  80. SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, native);
  81. }
  82. return ret;
  83. }
  84. static BOOL tgt_process_module_close_process(struct dbg_process* pcs, BOOL kill)
  85. {
  86. SymCleanup(pcs->handle);
  87. dbg_del_process(pcs);
  88. return TRUE;
  89. }
  90. static BOOL tgt_process_module_get_selector(HANDLE hThread, DWORD sel, LDT_ENTRY* le)
  91. {
  92. return FALSE;
  93. }
  94. static struct be_process_io be_process_module_io =
  95. {
  96. tgt_process_module_close_process,
  97. tgt_process_module_read,
  98. tgt_process_module_write,
  99. tgt_process_module_get_selector,
  100. };