tgt_module.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "config.h"
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdarg.h>
  25. #include "debugger.h"
  26. static struct be_process_io be_process_module_io;
  27. static BOOL tgt_process_module_read(HANDLE hProcess, const void* addr,
  28. void* buffer, SIZE_T len, SIZE_T* rlen)
  29. {
  30. return FALSE;
  31. }
  32. static BOOL tgt_process_module_write(HANDLE hProcess, void* addr,
  33. const void* buffer, SIZE_T len, SIZE_T* wlen)
  34. {
  35. return FALSE;
  36. }
  37. enum dbg_start tgt_module_load(const char* name, BOOL keep)
  38. {
  39. DWORD opts = SymGetOptions();
  40. BOOL native;
  41. HANDLE hDummy = (HANDLE)0x87654321;
  42. enum dbg_start ret = start_ok;
  43. WCHAR* nameW;
  44. unsigned len;
  45. SymSetOptions((opts & ~(SYMOPT_UNDNAME|SYMOPT_DEFERRED_LOADS)) |
  46. SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS);
  47. native = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
  48. if (!dbg_init(hDummy, NULL, FALSE))
  49. return start_error_init;
  50. len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
  51. nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
  52. if (!nameW)
  53. {
  54. ret = start_error_init;
  55. keep = FALSE;
  56. }
  57. else
  58. {
  59. len = MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, len);
  60. if (!dbg_load_module(hDummy, NULL, nameW, 0, 0))
  61. {
  62. ret = start_error_init;
  63. keep = FALSE;
  64. }
  65. HeapFree(GetProcessHeap(), 0, nameW);
  66. }
  67. if (keep)
  68. {
  69. dbg_printf("Non supported mode... errors may occur\n"
  70. "Use at your own risks\n");
  71. SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
  72. dbg_curr_process = dbg_add_process(&be_process_module_io, 1, hDummy);
  73. dbg_curr_pid = 1;
  74. dbg_curr_thread = dbg_add_thread(dbg_curr_process, 2, NULL, NULL);
  75. /* FIXME: missing thread creation, fetching frames, restoring dbghelp's options... */
  76. }
  77. else
  78. {
  79. SymCleanup(hDummy);
  80. SymSetOptions(opts);
  81. SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, native);
  82. }
  83. return ret;
  84. }
  85. static BOOL tgt_process_module_close_process(struct dbg_process* pcs, BOOL kill)
  86. {
  87. SymCleanup(pcs->handle);
  88. dbg_del_process(pcs);
  89. return TRUE;
  90. }
  91. static BOOL tgt_process_module_get_selector(HANDLE hThread, DWORD sel, LDT_ENTRY* le)
  92. {
  93. return FALSE;
  94. }
  95. static struct be_process_io be_process_module_io =
  96. {
  97. tgt_process_module_close_process,
  98. tgt_process_module_read,
  99. tgt_process_module_write,
  100. tgt_process_module_get_selector,
  101. };