phpdbg_bp.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Felipe Pena <felipe@php.net> |
  16. | Authors: Joe Watkins <joe.watkins@live.co.uk> |
  17. | Authors: Bob Weinand <bwoebi@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. #include "zend.h"
  21. #include "zend_hash.h"
  22. #include "phpdbg.h"
  23. #include "phpdbg_bp.h"
  24. #include "phpdbg_utils.h"
  25. #include "phpdbg_opcode.h"
  26. #include "zend_globals.h"
  27. ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
  28. /* {{{ private api functions */
  29. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array* TSRMLS_DC);
  30. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function* TSRMLS_DC);
  31. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array* TSRMLS_DC);
  32. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t TSRMLS_DC);
  33. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar TSRMLS_DC);
  34. static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data TSRMLS_DC); /* }}} */
  35. /*
  36. * Note:
  37. * A break point must always set the correct id and type
  38. * A set breakpoint function must always map new points
  39. */
  40. static inline void _phpdbg_break_mapping(int id, HashTable *table TSRMLS_DC)
  41. {
  42. zend_hash_index_update(
  43. &PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (id), (void**) &table, sizeof(void*), NULL);
  44. }
  45. #define PHPDBG_BREAK_MAPPING(id, table) _phpdbg_break_mapping(id, table TSRMLS_CC)
  46. #define PHPDBG_BREAK_UNMAPPING(id) \
  47. zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (id))
  48. #define PHPDBG_BREAK_INIT(b, t) do {\
  49. b.id = PHPDBG_G(bp_count)++; \
  50. b.type = t; \
  51. b.disabled = 0;\
  52. b.hits = 0; \
  53. } while(0)
  54. static void phpdbg_file_breaks_dtor(void *data) /* {{{ */
  55. {
  56. phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data;
  57. efree((char*)bp->filename);
  58. } /* }}} */
  59. static void phpdbg_class_breaks_dtor(void *data) /* {{{ */
  60. {
  61. phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t*) data;
  62. efree((char*)bp->class_name);
  63. efree((char*)bp->func_name);
  64. } /* }}} */
  65. static void phpdbg_opline_class_breaks_dtor(void *data) /* {{{ */
  66. {
  67. zend_hash_destroy((HashTable *)data);
  68. } /* }}} */
  69. static void phpdbg_opline_breaks_dtor(void *data) /* {{{ */
  70. {
  71. phpdbg_breakopline_t *bp = (phpdbg_breakopline_t *) data;
  72. if (bp->class_name) {
  73. efree((char*)bp->class_name);
  74. }
  75. if (bp->func_name) {
  76. efree((char*)bp->func_name);
  77. }
  78. } /* }}} */
  79. PHPDBG_API void phpdbg_reset_breakpoints(TSRMLS_D) /* {{{ */
  80. {
  81. if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) {
  82. HashPosition position[2];
  83. HashTable **table = NULL;
  84. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0]);
  85. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (void**)&table, &position[0]) == SUCCESS;
  86. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0])) {
  87. phpdbg_breakbase_t *brake;
  88. for (zend_hash_internal_pointer_reset_ex((*table), &position[1]);
  89. zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS;
  90. zend_hash_move_forward_ex((*table), &position[1])) {
  91. brake->hits = 0;
  92. }
  93. }
  94. }
  95. } /* }}} */
  96. PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
  97. {
  98. HashPosition position[2];
  99. HashTable **table = NULL;
  100. zend_ulong id = 0L;
  101. if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) {
  102. phpdbg_notice(
  103. "Exporting %d breakpoints",
  104. zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP]));
  105. /* this only looks like magic, it isn't */
  106. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0]);
  107. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (void**)&table, &position[0]) == SUCCESS;
  108. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0])) {
  109. phpdbg_breakbase_t *brake;
  110. zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], NULL, NULL, &id, 0, &position[0]);
  111. for (zend_hash_internal_pointer_reset_ex((*table), &position[1]);
  112. zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS;
  113. zend_hash_move_forward_ex((*table), &position[1])) {
  114. if (brake->id == id) {
  115. switch (brake->type) {
  116. case PHPDBG_BREAK_FILE: {
  117. fprintf(handle,
  118. "break %s:%lu\n",
  119. ((phpdbg_breakfile_t*)brake)->filename,
  120. ((phpdbg_breakfile_t*)brake)->line);
  121. } break;
  122. case PHPDBG_BREAK_SYM: {
  123. fprintf(handle,
  124. "break %s\n",
  125. ((phpdbg_breaksymbol_t*)brake)->symbol);
  126. } break;
  127. case PHPDBG_BREAK_METHOD: {
  128. fprintf(handle,
  129. "break %s::%s\n",
  130. ((phpdbg_breakmethod_t*)brake)->class_name,
  131. ((phpdbg_breakmethod_t*)brake)->func_name);
  132. } break;
  133. case PHPDBG_BREAK_METHOD_OPLINE: {
  134. fprintf(handle,
  135. "break %s::%s#%ld\n",
  136. ((phpdbg_breakopline_t*)brake)->class_name,
  137. ((phpdbg_breakopline_t*)brake)->func_name,
  138. ((phpdbg_breakopline_t*)brake)->opline_num);
  139. } break;
  140. case PHPDBG_BREAK_FUNCTION_OPLINE: {
  141. fprintf(handle,
  142. "break %s#%ld\n",
  143. ((phpdbg_breakopline_t*)brake)->func_name,
  144. ((phpdbg_breakopline_t*)brake)->opline_num);
  145. } break;
  146. case PHPDBG_BREAK_FILE_OPLINE: {
  147. fprintf(handle,
  148. "break %s:#%ld\n",
  149. ((phpdbg_breakopline_t*)brake)->class_name,
  150. ((phpdbg_breakopline_t*)brake)->opline_num);
  151. } break;
  152. case PHPDBG_BREAK_OPCODE: {
  153. fprintf(handle,
  154. "break %s\n",
  155. ((phpdbg_breakop_t*)brake)->name);
  156. } break;
  157. case PHPDBG_BREAK_COND: {
  158. phpdbg_breakcond_t *conditional = (phpdbg_breakcond_t*) brake;
  159. if (conditional->paramed) {
  160. switch (conditional->param.type) {
  161. case STR_PARAM:
  162. fprintf(handle,
  163. "break at %s if %s\n", conditional->param.str, conditional->code);
  164. break;
  165. case METHOD_PARAM:
  166. fprintf(handle,
  167. "break at %s::%s if %s\n",
  168. conditional->param.method.class, conditional->param.method.name,
  169. conditional->code);
  170. break;
  171. case FILE_PARAM:
  172. fprintf(handle,
  173. "break at %s:%lu if %s\n",
  174. conditional->param.file.name, conditional->param.file.line,
  175. conditional->code);
  176. break;
  177. default: { /* do nothing */ } break;
  178. }
  179. } else {
  180. fprintf(
  181. handle, "break if %s\n", conditional->code);
  182. }
  183. } break;
  184. }
  185. }
  186. }
  187. }
  188. }
  189. } /* }}} */
  190. PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */
  191. {
  192. php_stream_statbuf ssb;
  193. char realpath[MAXPATHLEN];
  194. if (php_stream_stat_path(path, &ssb) != FAILURE) {
  195. if (ssb.sb.st_mode & (S_IFREG|S_IFLNK)) {
  196. HashTable *broken;
  197. phpdbg_breakfile_t new_break;
  198. size_t path_len = 0L;
  199. if (VCWD_REALPATH(path, realpath)) {
  200. path = realpath;
  201. }
  202. path_len = strlen(path);
  203. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
  204. path, path_len, (void**)&broken) == FAILURE) {
  205. HashTable breaks;
  206. zend_hash_init(&breaks, 8, NULL, phpdbg_file_breaks_dtor, 0);
  207. zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
  208. path, path_len, &breaks, sizeof(HashTable),
  209. (void**)&broken);
  210. }
  211. if (!zend_hash_index_exists(broken, line_num)) {
  212. PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
  213. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_FILE);
  214. new_break.filename = estrndup(path, path_len);
  215. new_break.line = line_num;
  216. zend_hash_index_update(
  217. broken, line_num, (void**)&new_break, sizeof(phpdbg_breakfile_t), NULL);
  218. phpdbg_notice("Breakpoint #%d added at %s:%ld",
  219. new_break.id, new_break.filename, new_break.line);
  220. PHPDBG_BREAK_MAPPING(new_break.id, broken);
  221. } else {
  222. phpdbg_error("Breakpoint at %s:%ld exists", path, line_num);
  223. }
  224. } else {
  225. phpdbg_error("Cannot set breakpoint in %s, it is not a regular file", path);
  226. }
  227. } else {
  228. phpdbg_error("Cannot stat %s, it does not exist", path);
  229. }
  230. } /* }}} */
  231. PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len TSRMLS_DC) /* {{{ */
  232. {
  233. if (!zend_hash_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], name, name_len)) {
  234. phpdbg_breaksymbol_t new_break;
  235. PHPDBG_G(flags) |= PHPDBG_HAS_SYM_BP;
  236. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_SYM);
  237. new_break.symbol = estrndup(name, name_len);
  238. zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], new_break.symbol,
  239. name_len, &new_break, sizeof(phpdbg_breaksymbol_t), NULL);
  240. phpdbg_notice("Breakpoint #%d added at %s",
  241. new_break.id, new_break.symbol);
  242. PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
  243. } else {
  244. phpdbg_notice("Breakpoint exists at %s", name);
  245. }
  246. } /* }}} */
  247. PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char *func_name TSRMLS_DC) /* {{{ */
  248. {
  249. HashTable class_breaks, *class_table;
  250. size_t class_len = strlen(class_name);
  251. size_t func_len = strlen(func_name);
  252. char *lcname = zend_str_tolower_dup(func_name, func_len);
  253. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name,
  254. class_len, (void**)&class_table) != SUCCESS) {
  255. zend_hash_init(&class_breaks, 8, NULL, phpdbg_class_breaks_dtor, 0);
  256. zend_hash_update(
  257. &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD],
  258. class_name, class_len,
  259. (void**)&class_breaks, sizeof(HashTable), (void**)&class_table);
  260. }
  261. if (!zend_hash_exists(class_table, lcname, func_len)) {
  262. phpdbg_breakmethod_t new_break;
  263. PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_BP;
  264. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_METHOD);
  265. new_break.class_name = estrndup(class_name, class_len);
  266. new_break.class_len = class_len;
  267. new_break.func_name = estrndup(func_name, func_len);
  268. new_break.func_len = func_len;
  269. zend_hash_update(class_table, lcname, func_len,
  270. &new_break, sizeof(phpdbg_breakmethod_t), NULL);
  271. phpdbg_notice("Breakpoint #%d added at %s::%s",
  272. new_break.id, class_name, func_name);
  273. PHPDBG_BREAK_MAPPING(new_break.id, class_table);
  274. } else {
  275. phpdbg_notice("Breakpoint exists at %s::%s", class_name, func_name);
  276. }
  277. efree(lcname);
  278. } /* }}} */
  279. PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ */
  280. {
  281. if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline)) {
  282. phpdbg_breakline_t new_break;
  283. PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
  284. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_OPLINE);
  285. new_break.name = NULL;
  286. new_break.opline = opline;
  287. new_break.base = NULL;
  288. zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline,
  289. &new_break, sizeof(phpdbg_breakline_t), NULL);
  290. phpdbg_notice("Breakpoint #%d added at %#lx",
  291. new_break.id, new_break.opline);
  292. PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
  293. } else {
  294. phpdbg_notice("Breakpoint exists at %#lx", opline);
  295. }
  296. } /* }}} */
  297. PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array TSRMLS_DC) /* {{{ */
  298. {
  299. phpdbg_breakline_t opline_break;
  300. if (op_array->last <= brake->opline_num) {
  301. if (brake->class_name == NULL) {
  302. phpdbg_error("There are only %d oplines in function %s (breaking at opline %ld impossible)", op_array->last, brake->func_name, brake->opline_num);
  303. } else if (brake->func_name == NULL) {
  304. phpdbg_error("There are only %d oplines in file %s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->opline_num);
  305. } else {
  306. phpdbg_error("There are only %d oplines in method %s::%s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->func_name, brake->opline_num);
  307. }
  308. return FAILURE;
  309. }
  310. opline_break.disabled = 0;
  311. opline_break.hits = 0;
  312. opline_break.id = brake->id;
  313. opline_break.opline = brake->opline = (zend_ulong)(op_array->opcodes + brake->opline_num);
  314. opline_break.name = NULL;
  315. opline_break.base = brake;
  316. if (op_array->scope) {
  317. opline_break.type = PHPDBG_BREAK_METHOD_OPLINE;
  318. } else if (op_array->function_name) {
  319. opline_break.type = PHPDBG_BREAK_FUNCTION_OPLINE;
  320. } else {
  321. opline_break.type = PHPDBG_BREAK_FILE_OPLINE;
  322. }
  323. PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
  324. zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline_break.opline, &opline_break, sizeof(phpdbg_breakline_t), NULL);
  325. return SUCCESS;
  326. } /* }}} */
  327. PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array TSRMLS_DC) /* {{{ */
  328. {
  329. HashTable *func_table = &PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE];
  330. HashTable *oplines_table;
  331. HashPosition position;
  332. phpdbg_breakopline_t *brake;
  333. if (op_array->scope != NULL &&
  334. zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], op_array->scope->name, op_array->scope->name_length, (void **)&func_table) == FAILURE) {
  335. return;
  336. }
  337. if (op_array->function_name == NULL) {
  338. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], op_array->filename, strlen(op_array->filename), (void **)&oplines_table) == FAILURE) {
  339. return;
  340. }
  341. } else if (zend_hash_find(func_table, op_array->function_name?op_array->function_name:"", op_array->function_name?strlen(op_array->function_name):0, (void **)&oplines_table) == FAILURE) {
  342. return;
  343. }
  344. for (zend_hash_internal_pointer_reset_ex(oplines_table, &position);
  345. zend_hash_get_current_data_ex(oplines_table, (void**) &brake, &position) == SUCCESS;
  346. zend_hash_move_forward_ex(oplines_table, &position)) {
  347. if (phpdbg_resolve_op_array_break(brake, op_array TSRMLS_CC) == SUCCESS) {
  348. phpdbg_breakline_t *opline_break;
  349. zend_hash_internal_pointer_end(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
  350. zend_hash_get_current_data(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void **)&opline_break);
  351. phpdbg_notice("Breakpoint #%d resolved at %s%s%s#%ld (opline %#lx)",
  352. brake->id,
  353. brake->class_name?brake->class_name:"",
  354. brake->class_name&&brake->func_name?"::":"",
  355. brake->func_name?brake->func_name:"",
  356. brake->opline_num,
  357. brake->opline);
  358. }
  359. }
  360. } /* }}} */
  361. PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRMLS_DC) /* {{{ */
  362. {
  363. HashTable *func_table = EG(function_table);
  364. zend_function *func;
  365. if (new_break->func_name == NULL) {
  366. if (EG(current_execute_data) == NULL) {
  367. if (PHPDBG_G(ops) != NULL && !memcmp(PHPDBG_G(ops)->filename, new_break->class_name, new_break->class_len)) {
  368. if (phpdbg_resolve_op_array_break(new_break, PHPDBG_G(ops) TSRMLS_CC) == SUCCESS) {
  369. return SUCCESS;
  370. } else {
  371. return 2;
  372. }
  373. }
  374. return FAILURE;
  375. } else {
  376. zend_execute_data *execute_data = EG(current_execute_data);
  377. do {
  378. if (execute_data->op_array->function_name == NULL && execute_data->op_array->scope == NULL && !memcmp(execute_data->op_array->filename, new_break->class_name, new_break->class_len)) {
  379. if (phpdbg_resolve_op_array_break(new_break, execute_data->op_array TSRMLS_CC) == SUCCESS) {
  380. return SUCCESS;
  381. } else {
  382. return 2;
  383. }
  384. }
  385. } while ((execute_data = execute_data->prev_execute_data) != NULL);
  386. return FAILURE;
  387. }
  388. }
  389. if (new_break->class_name != NULL) {
  390. zend_class_entry **ce;
  391. if (zend_hash_find(EG(class_table), zend_str_tolower_dup(new_break->class_name, new_break->class_len), new_break->class_len + 1, (void **)&ce) == FAILURE) {
  392. return FAILURE;
  393. }
  394. func_table = &(*ce)->function_table;
  395. }
  396. if (zend_hash_find(func_table, zend_str_tolower_dup(new_break->func_name, new_break->func_len), new_break->func_len + 1, (void **)&func) == FAILURE) {
  397. if (new_break->class_name != NULL && new_break->func_name != NULL) {
  398. phpdbg_error("Method %s doesn't exist in class %s", new_break->func_name, new_break->class_name);
  399. return 2;
  400. }
  401. return FAILURE;
  402. }
  403. if (func->type != ZEND_USER_FUNCTION) {
  404. if (new_break->class_name == NULL) {
  405. phpdbg_error("%s is not an user defined function, no oplines exist", new_break->func_name);
  406. } else {
  407. phpdbg_error("%s::%s is not an user defined method, no oplines exist", new_break->class_name, new_break->func_name);
  408. }
  409. return 2;
  410. }
  411. if (phpdbg_resolve_op_array_break(new_break, &func->op_array TSRMLS_CC) == FAILURE) {
  412. return 2;
  413. }
  414. return SUCCESS;
  415. } /* }}} */
  416. PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline TSRMLS_DC) /* {{{ */
  417. {
  418. phpdbg_breakopline_t new_break;
  419. HashTable class_breaks, *class_table;
  420. HashTable method_breaks, *method_table;
  421. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_METHOD_OPLINE);
  422. new_break.func_len = strlen(method);
  423. new_break.func_name = estrndup(method, new_break.func_len);
  424. new_break.class_len = strlen(class);
  425. new_break.class_name = estrndup(class, new_break.class_len);
  426. new_break.opline_num = opline;
  427. new_break.opline = 0;
  428. switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) {
  429. case FAILURE:
  430. phpdbg_notice("Pending breakpoint #%d at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline);
  431. break;
  432. case SUCCESS:
  433. phpdbg_notice("Breakpoint #%d added at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline);
  434. break;
  435. case 2:
  436. return;
  437. }
  438. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], new_break.class_name, new_break.class_len, (void **)&class_table) == FAILURE) {
  439. zend_hash_init(&class_breaks, 8, NULL, phpdbg_opline_class_breaks_dtor, 0);
  440. zend_hash_update(
  441. &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE],
  442. new_break.class_name,
  443. new_break.class_len,
  444. (void **)&class_breaks, sizeof(HashTable), (void **)&class_table);
  445. }
  446. if (zend_hash_find(class_table, new_break.func_name, new_break.func_len, (void **)&method_table) == FAILURE) {
  447. zend_hash_init(&method_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0);
  448. zend_hash_update(
  449. class_table,
  450. new_break.func_name,
  451. new_break.func_len,
  452. (void **)&method_breaks, sizeof(HashTable), (void **)&method_table);
  453. }
  454. if (zend_hash_index_exists(method_table, opline)) {
  455. phpdbg_notice("Breakpoint already exists for %s::%s#%ld", new_break.class_name, new_break.func_name, opline);
  456. efree((char*)new_break.func_name);
  457. efree((char*)new_break.class_name);
  458. PHPDBG_G(bp_count)--;
  459. return;
  460. }
  461. PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_OPLINE_BP;
  462. PHPDBG_BREAK_MAPPING(new_break.id, method_table);
  463. zend_hash_index_update(method_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL);
  464. }
  465. PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline TSRMLS_DC) /* {{{ */
  466. {
  467. phpdbg_breakopline_t new_break;
  468. HashTable func_breaks, *func_table;
  469. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_FUNCTION_OPLINE);
  470. new_break.func_len = strlen(function);
  471. new_break.func_name = estrndup(function, new_break.func_len);
  472. new_break.class_len = 0;
  473. new_break.class_name = NULL;
  474. new_break.opline_num = opline;
  475. new_break.opline = 0;
  476. switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) {
  477. case FAILURE:
  478. phpdbg_notice("Pending breakpoint #%d at %s#%ld", new_break.id, new_break.func_name, opline);
  479. break;
  480. case SUCCESS:
  481. phpdbg_notice("Breakpoint #%d added at %s#%ld", new_break.id, new_break.func_name, opline);
  482. break;
  483. case 2:
  484. return;
  485. }
  486. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], new_break.func_name, new_break.func_len, (void **)&func_table) == FAILURE) {
  487. zend_hash_init(&func_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0);
  488. zend_hash_update(
  489. &PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE],
  490. new_break.func_name,
  491. new_break.func_len,
  492. (void **)&func_breaks, sizeof(HashTable), (void **)&func_table);
  493. }
  494. if (zend_hash_index_exists(func_table, opline)) {
  495. phpdbg_notice("Breakpoint already exists for %s#%ld", new_break.func_name, opline);
  496. efree((char*)new_break.func_name);
  497. PHPDBG_G(bp_count)--;
  498. return;
  499. }
  500. PHPDBG_BREAK_MAPPING(new_break.id, func_table);
  501. PHPDBG_G(flags) |= PHPDBG_HAS_FUNCTION_OPLINE_BP;
  502. zend_hash_index_update(func_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL);
  503. }
  504. PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline TSRMLS_DC) /* {{{ */
  505. {
  506. phpdbg_breakopline_t new_break;
  507. HashTable file_breaks, *file_table;
  508. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_FILE_OPLINE);
  509. new_break.func_len = 0;
  510. new_break.func_name = NULL;
  511. new_break.class_len = strlen(file);
  512. new_break.class_name = estrndup(file, new_break.class_len);
  513. new_break.opline_num = opline;
  514. new_break.opline = 0;
  515. switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) {
  516. case FAILURE:
  517. phpdbg_notice("Pending breakpoint #%d at %s:%ld", new_break.id, new_break.class_name, opline);
  518. break;
  519. case SUCCESS:
  520. phpdbg_notice("Breakpoint #%d added at %s:%ld", new_break.id, new_break.class_name, opline);
  521. break;
  522. case 2:
  523. return;
  524. }
  525. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], new_break.class_name, new_break.class_len, (void **)&file_table) == FAILURE) {
  526. zend_hash_init(&file_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0);
  527. zend_hash_update(
  528. &PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE],
  529. new_break.class_name,
  530. new_break.class_len,
  531. (void **)&file_breaks, sizeof(HashTable), (void **)&file_table);
  532. }
  533. if (zend_hash_index_exists(file_table, opline)) {
  534. phpdbg_notice("Breakpoint already exists for %s:%ld", new_break.class_name, opline);
  535. efree((char*)new_break.class_name);
  536. PHPDBG_G(bp_count)--;
  537. return;
  538. }
  539. PHPDBG_BREAK_MAPPING(new_break.id, file_table);
  540. PHPDBG_G(flags) |= PHPDBG_HAS_FILE_OPLINE_BP;
  541. zend_hash_index_update(file_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL);
  542. }
  543. PHPDBG_API void phpdbg_set_breakpoint_opcode(const char *name, size_t name_len TSRMLS_DC) /* {{{ */
  544. {
  545. phpdbg_breakop_t new_break;
  546. zend_ulong hash = zend_hash_func(name, name_len);
  547. if (zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash)) {
  548. phpdbg_notice(
  549. "Breakpoint exists for %s", name);
  550. return;
  551. }
  552. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_OPCODE);
  553. new_break.hash = hash;
  554. new_break.name = estrndup(name, name_len);
  555. zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash,
  556. &new_break, sizeof(phpdbg_breakop_t), NULL);
  557. PHPDBG_G(flags) |= PHPDBG_HAS_OPCODE_BP;
  558. phpdbg_notice("Breakpoint #%d added at %s", new_break.id, name);
  559. PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE]);
  560. } /* }}} */
  561. PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
  562. {
  563. if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline)) {
  564. phpdbg_breakline_t new_break;
  565. PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
  566. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_OPLINE);
  567. new_break.opline = (zend_ulong) opline;
  568. new_break.base = NULL;
  569. zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE],
  570. (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
  571. phpdbg_notice("Breakpoint #%d added at %#lx",
  572. new_break.id, new_break.opline);
  573. PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
  574. }
  575. } /* }}} */
  576. static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, const phpdbg_param_t *param, const char *expr, size_t expr_len, zend_ulong hash TSRMLS_DC) /* {{{ */
  577. {
  578. phpdbg_breakcond_t new_break;
  579. zend_uint cops = CG(compiler_options);
  580. zval pv;
  581. PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_COND);
  582. new_break.hash = hash;
  583. if (param) {
  584. new_break.paramed = 1;
  585. phpdbg_copy_param(
  586. param, &new_break.param TSRMLS_CC);
  587. } else {
  588. new_break.paramed = 0;
  589. }
  590. cops = CG(compiler_options);
  591. CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
  592. new_break.code = estrndup(expr, expr_len);
  593. new_break.code_len = expr_len;
  594. Z_STRLEN(pv) = expr_len + sizeof("return ;") - 1;
  595. Z_STRVAL(pv) = emalloc(Z_STRLEN(pv) + 1);
  596. memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
  597. memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, expr, expr_len);
  598. Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
  599. Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
  600. Z_TYPE(pv) = IS_STRING;
  601. new_break.ops = zend_compile_string(
  602. &pv, "Conditional Breakpoint Code" TSRMLS_CC);
  603. zval_dtor(&pv);
  604. if (new_break.ops) {
  605. zend_hash_index_update(
  606. &PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash, &new_break,
  607. sizeof(phpdbg_breakcond_t), (void**)&brake);
  608. phpdbg_notice("Conditional breakpoint #%d added %s/%p",
  609. brake->id, brake->code, brake->ops);
  610. PHPDBG_G(flags) |= PHPDBG_HAS_COND_BP;
  611. PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_COND]);
  612. } else {
  613. phpdbg_error(
  614. "Failed to compile code for expression %s", expr);
  615. efree((char*)new_break.code);
  616. PHPDBG_G(bp_count)--;
  617. }
  618. CG(compiler_options) = cops;
  619. } /* }}} */
  620. PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_len TSRMLS_DC) /* {{{ */
  621. {
  622. zend_ulong expr_hash = zend_inline_hash_func(expr, expr_len);
  623. phpdbg_breakcond_t new_break;
  624. if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], expr_hash)) {
  625. phpdbg_create_conditional_break(
  626. &new_break, NULL, expr, expr_len, expr_hash TSRMLS_CC);
  627. } else {
  628. phpdbg_notice("Conditional break %s exists", expr);
  629. }
  630. } /* }}} */
  631. PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */
  632. {
  633. phpdbg_breakcond_t new_break;
  634. phpdbg_param_t *condition;
  635. zend_ulong hash = 0L;
  636. if (param->next) {
  637. condition = param->next;
  638. hash = zend_inline_hash_func(condition->str, condition->len);
  639. if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash)) {
  640. phpdbg_create_conditional_break(
  641. &new_break, param,
  642. condition->str, condition->len, hash TSRMLS_CC);
  643. } else {
  644. phpdbg_notice(
  645. "Conditional break %s exists at the specified location", condition->str);
  646. }
  647. }
  648. } /* }}} */
  649. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
  650. {
  651. HashTable *breaks;
  652. phpdbg_breakbase_t *brake;
  653. size_t name_len = strlen(op_array->filename);
  654. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], op_array->filename,
  655. name_len, (void**)&breaks) == FAILURE) {
  656. return NULL;
  657. }
  658. if (zend_hash_index_find(breaks, (*EG(opline_ptr))->lineno, (void**)&brake) == SUCCESS) {
  659. return brake;
  660. }
  661. return NULL;
  662. } /* }}} */
  663. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */
  664. {
  665. const char *fname;
  666. zend_op_array *ops;
  667. phpdbg_breakbase_t *brake;
  668. if (fbc->type != ZEND_USER_FUNCTION) {
  669. return NULL;
  670. }
  671. ops = (zend_op_array*)fbc;
  672. if (ops->scope) {
  673. /* find method breaks here */
  674. return phpdbg_find_breakpoint_method(ops TSRMLS_CC);
  675. }
  676. fname = ops->function_name;
  677. if (!fname) {
  678. fname = "main";
  679. }
  680. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname, strlen(fname), (void**)&brake) == SUCCESS) {
  681. return brake;
  682. }
  683. return NULL;
  684. } /* }}} */
  685. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array *ops TSRMLS_DC) /* {{{ */
  686. {
  687. HashTable *class_table;
  688. phpdbg_breakbase_t *brake;
  689. if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], ops->scope->name,
  690. ops->scope->name_length, (void**)&class_table) == SUCCESS) {
  691. char *lcname = zend_str_tolower_dup(ops->function_name, strlen(ops->function_name));
  692. size_t lcname_len = strlen(lcname);
  693. if (zend_hash_find(
  694. class_table,
  695. lcname,
  696. lcname_len, (void**)&brake) == SUCCESS) {
  697. efree(lcname);
  698. return brake;
  699. }
  700. efree(lcname);
  701. }
  702. return NULL;
  703. } /* }}} */
  704. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
  705. {
  706. phpdbg_breakline_t *brake;
  707. if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE],
  708. (zend_ulong) opline, (void**)&brake) == SUCCESS) {
  709. return (brake->base?(phpdbg_breakbase_t *)brake->base:(phpdbg_breakbase_t *)brake);
  710. }
  711. return NULL;
  712. } /* }}} */
  713. static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar opcode TSRMLS_DC) /* {{{ */
  714. {
  715. phpdbg_breakbase_t *brake;
  716. const char *opname = phpdbg_decode_opcode(opcode);
  717. if (memcmp(opname, PHPDBG_STRL("UNKNOWN")) == 0) {
  718. return NULL;
  719. }
  720. if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE],
  721. zend_hash_func(opname, strlen(opname)), (void**)&brake) == SUCCESS) {
  722. return brake;
  723. }
  724. return NULL;
  725. } /* }}} */
  726. static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
  727. {
  728. zend_function *function = (zend_function*) execute_data->function_state.function;
  729. switch (param->type) {
  730. case NUMERIC_FUNCTION_PARAM:
  731. case STR_PARAM: {
  732. /* function breakpoint */
  733. if (function->type != ZEND_USER_FUNCTION) {
  734. return 0;
  735. }
  736. {
  737. const char *str = NULL;
  738. size_t len = 0L;
  739. zend_op_array *ops = (zend_op_array*)function;
  740. str = ops->function_name ? ops->function_name : "main";
  741. len = strlen(str);
  742. if (len == param->len && memcmp(param->str, str, len) == SUCCESS) {
  743. return param->type == STR_PARAM || execute_data->opline - ops->opcodes == param->num;
  744. }
  745. }
  746. } break;
  747. case FILE_PARAM: {
  748. if (param->file.line == zend_get_executed_lineno(TSRMLS_C)) {
  749. const char *str = zend_get_executed_filename(TSRMLS_C);
  750. size_t lengths[2] = {strlen(param->file.name), strlen(str)};
  751. if (lengths[0] == lengths[1]) {
  752. return (memcmp(
  753. param->file.name, str, lengths[0]) == SUCCESS);
  754. }
  755. }
  756. } break;
  757. case NUMERIC_METHOD_PARAM:
  758. case METHOD_PARAM: {
  759. if (function->type != ZEND_USER_FUNCTION) {
  760. return 0;
  761. }
  762. {
  763. zend_op_array *ops = (zend_op_array*) function;
  764. if (ops->scope) {
  765. size_t lengths[2] = {strlen(param->method.class), ops->scope->name_length};
  766. if (lengths[0] == lengths[1] && memcmp(param->method.class, ops->scope->name, lengths[0]) == SUCCESS) {
  767. lengths[0] = strlen(param->method.name);
  768. lengths[1] = strlen(ops->function_name);
  769. if (lengths[0] == lengths[1] && memcmp(param->method.name, ops->function_name, lengths[0]) == SUCCESS) {
  770. return param->type == METHOD_PARAM || (execute_data->opline - ops->opcodes) == param->num;
  771. }
  772. }
  773. }
  774. }
  775. } break;
  776. case ADDR_PARAM: {
  777. return ((zend_ulong)(phpdbg_opline_ptr_t)execute_data->opline == param->addr);
  778. } break;
  779. default: {
  780. /* do nothing */
  781. } break;
  782. }
  783. return 0;
  784. } /* }}} */
  785. static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
  786. {
  787. phpdbg_breakcond_t *bp;
  788. HashPosition position;
  789. int breakpoint = FAILURE;
  790. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position);
  791. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void*)&bp, &position) == SUCCESS;
  792. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) {
  793. zval *retval = NULL;
  794. int orig_interactive = CG(interactive);
  795. zval **orig_retval = EG(return_value_ptr_ptr);
  796. zend_op_array *orig_ops = EG(active_op_array);
  797. zend_op **orig_opline = EG(opline_ptr);
  798. if (((phpdbg_breakbase_t*)bp)->disabled) {
  799. continue;
  800. }
  801. if (bp->paramed) {
  802. if (!phpdbg_find_breakpoint_param(&bp->param, execute_data TSRMLS_CC)) {
  803. continue;
  804. }
  805. }
  806. ALLOC_INIT_ZVAL(retval);
  807. EG(return_value_ptr_ptr) = &retval;
  808. EG(active_op_array) = bp->ops;
  809. EG(no_extensions) = 1;
  810. if (!EG(active_symbol_table)) {
  811. zend_rebuild_symbol_table(TSRMLS_C);
  812. }
  813. CG(interactive) = 0;
  814. zend_try {
  815. PHPDBG_G(flags) |= PHPDBG_IN_COND_BP;
  816. zend_execute(EG(active_op_array) TSRMLS_CC);
  817. #if PHP_VERSION_ID >= 50700
  818. if (zend_is_true(retval TSRMLS_CC)) {
  819. #else
  820. if (zend_is_true(retval)) {
  821. #endif
  822. breakpoint = SUCCESS;
  823. }
  824. } zend_catch {
  825. CG(interactive) = orig_interactive;
  826. EG(no_extensions)=1;
  827. EG(return_value_ptr_ptr) = orig_retval;
  828. EG(active_op_array) = orig_ops;
  829. EG(opline_ptr) = orig_opline;
  830. PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP;
  831. } zend_end_try();
  832. CG(interactive) = orig_interactive;
  833. EG(no_extensions)=1;
  834. EG(return_value_ptr_ptr) = orig_retval;
  835. EG(active_op_array) = orig_ops;
  836. EG(opline_ptr) = orig_opline;
  837. PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP;
  838. if (breakpoint == SUCCESS) {
  839. break;
  840. }
  841. }
  842. return (breakpoint == SUCCESS) ? ((phpdbg_breakbase_t*)bp) : NULL;
  843. } /* }}} */
  844. PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakpoint(zend_execute_data* execute_data TSRMLS_DC) /* {{{ */
  845. {
  846. phpdbg_breakbase_t *base = NULL;
  847. if (!(PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED)) {
  848. return NULL;
  849. }
  850. /* conditions cannot be executed by eval()'d code */
  851. if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL) &&
  852. (PHPDBG_G(flags) & PHPDBG_HAS_COND_BP) &&
  853. (base = phpdbg_find_conditional_breakpoint(execute_data TSRMLS_CC))) {
  854. goto result;
  855. }
  856. if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP) &&
  857. (base = phpdbg_find_breakpoint_file(execute_data->op_array TSRMLS_CC))) {
  858. goto result;
  859. }
  860. if (PHPDBG_G(flags) & (PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_SYM_BP)) {
  861. /* check we are at the beginning of the stack */
  862. if (execute_data->opline == EG(active_op_array)->opcodes) {
  863. if ((base = phpdbg_find_breakpoint_symbol(
  864. execute_data->function_state.function TSRMLS_CC))) {
  865. goto result;
  866. }
  867. }
  868. }
  869. if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP) &&
  870. (base = phpdbg_find_breakpoint_opline(execute_data->opline TSRMLS_CC))) {
  871. goto result;
  872. }
  873. if ((PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) &&
  874. (base = phpdbg_find_breakpoint_opcode(execute_data->opline->opcode TSRMLS_CC))) {
  875. goto result;
  876. }
  877. return NULL;
  878. result:
  879. /* we return nothing for disable breakpoints */
  880. if (base->disabled) {
  881. return NULL;
  882. }
  883. return base;
  884. } /* }}} */
  885. PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */
  886. {
  887. HashTable **table;
  888. HashPosition position;
  889. phpdbg_breakbase_t *brake;
  890. if ((brake = phpdbg_find_breakbase_ex(num, &table, &position TSRMLS_CC))) {
  891. char *key;
  892. zend_uint klen;
  893. zend_ulong idx;
  894. int type = brake->type;
  895. char *name = NULL;
  896. size_t name_len = 0L;
  897. switch (type) {
  898. case PHPDBG_BREAK_FILE:
  899. case PHPDBG_BREAK_METHOD:
  900. if (zend_hash_num_elements((*table)) == 1) {
  901. name = estrdup(brake->name);
  902. name_len = strlen(name);
  903. if (zend_hash_num_elements(&PHPDBG_G(bp)[type]) == 1) {
  904. PHPDBG_G(flags) &= ~(1<<(brake->type+1));
  905. }
  906. }
  907. break;
  908. default: {
  909. if (zend_hash_num_elements((*table)) == 1) {
  910. PHPDBG_G(flags) &= ~(1<<(brake->type+1));
  911. }
  912. }
  913. }
  914. switch (type) {
  915. case PHPDBG_BREAK_FILE_OPLINE:
  916. case PHPDBG_BREAK_FUNCTION_OPLINE:
  917. case PHPDBG_BREAK_METHOD_OPLINE:
  918. if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]) == 1) {
  919. PHPDBG_G(flags) &= PHPDBG_HAS_OPLINE_BP;
  920. }
  921. zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], ((phpdbg_breakopline_t*)brake)->opline);
  922. }
  923. switch (zend_hash_get_current_key_ex(
  924. (*table), &key, &klen, &idx, 0, &position)) {
  925. case HASH_KEY_IS_STRING:
  926. zend_hash_del((*table), key, klen);
  927. break;
  928. default:
  929. zend_hash_index_del((*table), idx);
  930. }
  931. switch (type) {
  932. case PHPDBG_BREAK_FILE:
  933. case PHPDBG_BREAK_METHOD:
  934. if (name) {
  935. zend_hash_del(&PHPDBG_G(bp)[type], name, name_len);
  936. efree(name);
  937. }
  938. break;
  939. }
  940. phpdbg_notice("Deleted breakpoint #%ld", num);
  941. PHPDBG_BREAK_UNMAPPING(num);
  942. } else {
  943. phpdbg_error("Failed to find breakpoint #%ld", num);
  944. }
  945. } /* }}} */
  946. PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */
  947. {
  948. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
  949. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
  950. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
  951. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]);
  952. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE]);
  953. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE]);
  954. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE]);
  955. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]);
  956. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]);
  957. zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP]);
  958. PHPDBG_G(flags) &= ~PHPDBG_BP_MASK;
  959. PHPDBG_G(bp_count) = 0;
  960. } /* }}} */
  961. PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t *brake, zend_bool output TSRMLS_DC) /* {{{ */
  962. {
  963. brake->hits++;
  964. if (output) {
  965. phpdbg_print_breakpoint(brake TSRMLS_CC);
  966. }
  967. } /* }}} */
  968. PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake TSRMLS_DC) /* {{{ */
  969. {
  970. if (!brake)
  971. goto unknown;
  972. switch (brake->type) {
  973. case PHPDBG_BREAK_FILE: {
  974. phpdbg_notice("Breakpoint #%d at %s:%ld, hits: %lu",
  975. ((phpdbg_breakfile_t*)brake)->id,
  976. ((phpdbg_breakfile_t*)brake)->filename,
  977. ((phpdbg_breakfile_t*)brake)->line,
  978. ((phpdbg_breakfile_t*)brake)->hits);
  979. } break;
  980. case PHPDBG_BREAK_SYM: {
  981. phpdbg_notice("Breakpoint #%d in %s() at %s:%u, hits: %lu",
  982. ((phpdbg_breaksymbol_t*)brake)->id,
  983. ((phpdbg_breaksymbol_t*)brake)->symbol,
  984. zend_get_executed_filename(TSRMLS_C),
  985. zend_get_executed_lineno(TSRMLS_C),
  986. ((phpdbg_breakfile_t*)brake)->hits);
  987. } break;
  988. case PHPDBG_BREAK_OPLINE: {
  989. phpdbg_notice("Breakpoint #%d in %#lx at %s:%u, hits: %lu",
  990. ((phpdbg_breakline_t*)brake)->id,
  991. ((phpdbg_breakline_t*)brake)->opline,
  992. zend_get_executed_filename(TSRMLS_C),
  993. zend_get_executed_lineno(TSRMLS_C),
  994. ((phpdbg_breakline_t*)brake)->hits);
  995. } break;
  996. case PHPDBG_BREAK_METHOD_OPLINE: {
  997. phpdbg_notice("Breakpoint #%d in %s::%s()#%lu at %s:%u, hits: %lu",
  998. ((phpdbg_breakopline_t*)brake)->id,
  999. ((phpdbg_breakopline_t*)brake)->class_name,
  1000. ((phpdbg_breakopline_t*)brake)->func_name,
  1001. ((phpdbg_breakopline_t*)brake)->opline_num,
  1002. zend_get_executed_filename(TSRMLS_C),
  1003. zend_get_executed_lineno(TSRMLS_C),
  1004. ((phpdbg_breakopline_t*)brake)->hits);
  1005. } break;
  1006. case PHPDBG_BREAK_FUNCTION_OPLINE: {
  1007. phpdbg_notice("Breakpoint #%d in %s()#%lu at %s:%u, hits: %lu",
  1008. ((phpdbg_breakopline_t*)brake)->id,
  1009. ((phpdbg_breakopline_t*)brake)->func_name,
  1010. ((phpdbg_breakopline_t*)brake)->opline_num,
  1011. zend_get_executed_filename(TSRMLS_C),
  1012. zend_get_executed_lineno(TSRMLS_C),
  1013. ((phpdbg_breakopline_t*)brake)->hits);
  1014. } break;
  1015. case PHPDBG_BREAK_FILE_OPLINE: {
  1016. phpdbg_notice("Breakpoint #%d in %s:%lu at %s:%u, hits: %lu",
  1017. ((phpdbg_breakopline_t*)brake)->id,
  1018. ((phpdbg_breakopline_t*)brake)->class_name,
  1019. ((phpdbg_breakopline_t*)brake)->opline_num,
  1020. zend_get_executed_filename(TSRMLS_C),
  1021. zend_get_executed_lineno(TSRMLS_C),
  1022. ((phpdbg_breakopline_t*)brake)->hits);
  1023. } break;
  1024. case PHPDBG_BREAK_OPCODE: {
  1025. phpdbg_notice("Breakpoint #%d in %s at %s:%u, hits: %lu",
  1026. ((phpdbg_breakop_t*)brake)->id,
  1027. ((phpdbg_breakop_t*)brake)->name,
  1028. zend_get_executed_filename(TSRMLS_C),
  1029. zend_get_executed_lineno(TSRMLS_C),
  1030. ((phpdbg_breakop_t*)brake)->hits);
  1031. } break;
  1032. case PHPDBG_BREAK_METHOD: {
  1033. phpdbg_notice("Breakpoint #%d in %s::%s() at %s:%u, hits: %lu",
  1034. ((phpdbg_breakmethod_t*)brake)->id,
  1035. ((phpdbg_breakmethod_t*)brake)->class_name,
  1036. ((phpdbg_breakmethod_t*)brake)->func_name,
  1037. zend_get_executed_filename(TSRMLS_C),
  1038. zend_get_executed_lineno(TSRMLS_C),
  1039. ((phpdbg_breakmethod_t*)brake)->hits);
  1040. } break;
  1041. case PHPDBG_BREAK_COND: {
  1042. if (((phpdbg_breakcond_t*)brake)->paramed) {
  1043. char *param;
  1044. phpdbg_notice("Conditional breakpoint #%d: at %s if %s %s:%u, hits: %lu",
  1045. ((phpdbg_breakcond_t*)brake)->id,
  1046. phpdbg_param_tostring(&((phpdbg_breakcond_t*)brake)->param, &param TSRMLS_CC),
  1047. ((phpdbg_breakcond_t*)brake)->code,
  1048. zend_get_executed_filename(TSRMLS_C),
  1049. zend_get_executed_lineno(TSRMLS_C),
  1050. ((phpdbg_breakcond_t*)brake)->hits);
  1051. if (param)
  1052. free(param);
  1053. } else {
  1054. phpdbg_notice("Conditional breakpoint #%d: on %s == true %s:%u, hits: %lu",
  1055. ((phpdbg_breakcond_t*)brake)->id,
  1056. ((phpdbg_breakcond_t*)brake)->code,
  1057. zend_get_executed_filename(TSRMLS_C),
  1058. zend_get_executed_lineno(TSRMLS_C),
  1059. ((phpdbg_breakcond_t*)brake)->hits);
  1060. }
  1061. } break;
  1062. default: {
  1063. unknown:
  1064. phpdbg_notice("Unknown breakpoint at %s:%u",
  1065. zend_get_executed_filename(TSRMLS_C),
  1066. zend_get_executed_lineno(TSRMLS_C));
  1067. }
  1068. }
  1069. } /* }}} */
  1070. PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id TSRMLS_DC) /* {{{ */
  1071. {
  1072. phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id TSRMLS_CC);
  1073. if (brake) {
  1074. brake->disabled = 0;
  1075. }
  1076. } /* }}} */
  1077. PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id TSRMLS_DC) /* {{{ */
  1078. {
  1079. phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id TSRMLS_CC);
  1080. if (brake) {
  1081. brake->disabled = 1;
  1082. }
  1083. } /* }}} */
  1084. PHPDBG_API void phpdbg_enable_breakpoints(TSRMLS_D) /* {{{ */
  1085. {
  1086. PHPDBG_G(flags) |= PHPDBG_IS_BP_ENABLED;
  1087. } /* }}} */
  1088. PHPDBG_API void phpdbg_disable_breakpoints(TSRMLS_D) { /* {{{ */
  1089. PHPDBG_G(flags) &= ~PHPDBG_IS_BP_ENABLED;
  1090. } /* }}} */
  1091. PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id TSRMLS_DC) /* {{{ */
  1092. {
  1093. HashTable **table;
  1094. HashPosition position;
  1095. return phpdbg_find_breakbase_ex(id, &table, &position TSRMLS_CC);
  1096. } /* }}} */
  1097. PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable ***table, HashPosition *position TSRMLS_DC) /* {{{ */
  1098. {
  1099. if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, (void**)table) == SUCCESS) {
  1100. phpdbg_breakbase_t *brake;
  1101. for (zend_hash_internal_pointer_reset_ex((**table), position);
  1102. zend_hash_get_current_data_ex((**table), (void**)&brake, position) == SUCCESS;
  1103. zend_hash_move_forward_ex((**table), position)) {
  1104. if (brake->id == id) {
  1105. return brake;
  1106. }
  1107. }
  1108. }
  1109. return NULL;
  1110. } /* }}} */
  1111. PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */
  1112. {
  1113. switch (type) {
  1114. case PHPDBG_BREAK_SYM: if ((PHPDBG_G(flags) & PHPDBG_HAS_SYM_BP)) {
  1115. HashPosition position;
  1116. phpdbg_breaksymbol_t *brake;
  1117. phpdbg_writeln(SEPARATE);
  1118. phpdbg_writeln("Function Breakpoints:");
  1119. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position);
  1120. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], (void**) &brake, &position) == SUCCESS;
  1121. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position)) {
  1122. phpdbg_writeln("#%d\t\t%s%s",
  1123. brake->id, brake->symbol,
  1124. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1125. }
  1126. } break;
  1127. case PHPDBG_BREAK_METHOD: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_BP)) {
  1128. HashPosition position[2];
  1129. HashTable *class_table;
  1130. char *class_name = NULL;
  1131. zend_uint class_len = 0;
  1132. zend_ulong class_idx = 0L;
  1133. phpdbg_writeln(SEPARATE);
  1134. phpdbg_writeln("Method Breakpoints:");
  1135. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0]);
  1136. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], (void**) &class_table, &position[0]) == SUCCESS;
  1137. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0])) {
  1138. if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD],
  1139. &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
  1140. phpdbg_breakmethod_t *brake;
  1141. for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]);
  1142. zend_hash_get_current_data_ex(class_table, (void**)&brake, &position[1]) == SUCCESS;
  1143. zend_hash_move_forward_ex(class_table, &position[1])) {
  1144. phpdbg_writeln("#%d\t\t%s::%s%s",
  1145. brake->id, brake->class_name, brake->func_name,
  1146. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1147. }
  1148. }
  1149. }
  1150. } break;
  1151. case PHPDBG_BREAK_FILE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)) {
  1152. HashPosition position[2];
  1153. HashTable *points;
  1154. phpdbg_writeln(SEPARATE);
  1155. phpdbg_writeln("File Breakpoints:");
  1156. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position[0]);
  1157. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], (void**) &points, &position[0]) == SUCCESS;
  1158. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position[0])) {
  1159. phpdbg_breakfile_t *brake;
  1160. for (zend_hash_internal_pointer_reset_ex(points, &position[1]);
  1161. zend_hash_get_current_data_ex(points, (void**)&brake, &position[1]) == SUCCESS;
  1162. zend_hash_move_forward_ex(points, &position[1])) {
  1163. phpdbg_writeln("#%d\t\t%s:%lu%s",
  1164. brake->id, brake->filename, brake->line,
  1165. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1166. }
  1167. }
  1168. } break;
  1169. case PHPDBG_BREAK_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)) {
  1170. HashPosition position;
  1171. phpdbg_breakline_t *brake;
  1172. phpdbg_writeln(SEPARATE);
  1173. phpdbg_writeln("Opline Breakpoints:");
  1174. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position);
  1175. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void**) &brake, &position) == SUCCESS;
  1176. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position)) {
  1177. switch (brake->type) {
  1178. case PHPDBG_BREAK_METHOD_OPLINE:
  1179. case PHPDBG_BREAK_FUNCTION_OPLINE:
  1180. case PHPDBG_BREAK_FILE_OPLINE:
  1181. phpdbg_writeln("#%d\t\t%#lx\t\t(%s breakpoint)%s", brake->id, brake->opline,
  1182. brake->type == PHPDBG_BREAK_METHOD_OPLINE?"method":
  1183. brake->type == PHPDBG_BREAK_FUNCTION_OPLINE?"function":
  1184. brake->type == PHPDBG_BREAK_FILE_OPLINE?"file":
  1185. "--- error ---",
  1186. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1187. break;
  1188. default:
  1189. phpdbg_writeln("#%d\t\t%#lx", brake->id, brake->opline);
  1190. break;
  1191. }
  1192. }
  1193. } break;
  1194. case PHPDBG_BREAK_METHOD_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_OPLINE_BP)) {
  1195. HashPosition position[3];
  1196. HashTable *class_table, *method_table;
  1197. char *class_name = NULL, *method_name = NULL;
  1198. zend_uint class_len = 0, method_len = 0;
  1199. zend_ulong class_idx = 0L, method_idx = 0L;
  1200. phpdbg_writeln(SEPARATE);
  1201. phpdbg_writeln("Method opline Breakpoints:");
  1202. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], &position[0]);
  1203. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], (void**) &class_table, &position[0]) == SUCCESS;
  1204. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], &position[0])) {
  1205. if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE],
  1206. &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
  1207. for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]);
  1208. zend_hash_get_current_data_ex(class_table, (void**) &method_table, &position[1]) == SUCCESS;
  1209. zend_hash_move_forward_ex(class_table, &position[1])) {
  1210. if (zend_hash_get_current_key_ex(class_table,
  1211. &method_name, &method_len, &method_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
  1212. phpdbg_breakopline_t *brake;
  1213. for (zend_hash_internal_pointer_reset_ex(method_table, &position[2]);
  1214. zend_hash_get_current_data_ex(method_table, (void**)&brake, &position[2]) == SUCCESS;
  1215. zend_hash_move_forward_ex(method_table, &position[2])) {
  1216. phpdbg_writeln("#%d\t\t%s::%s opline %ld%s",
  1217. brake->id, brake->class_name, brake->func_name, brake->opline_num,
  1218. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }
  1224. } break;
  1225. case PHPDBG_BREAK_FUNCTION_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FUNCTION_OPLINE_BP)) {
  1226. HashPosition position[2];
  1227. HashTable *function_table;
  1228. char *function_name = NULL;
  1229. zend_uint function_len = 0;
  1230. zend_ulong function_idx = 0L;
  1231. phpdbg_writeln(SEPARATE);
  1232. phpdbg_writeln("Function opline Breakpoints:");
  1233. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], &position[0]);
  1234. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], (void**) &function_table, &position[0]) == SUCCESS;
  1235. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], &position[0])) {
  1236. if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE],
  1237. &function_name, &function_len, &function_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
  1238. phpdbg_breakopline_t *brake;
  1239. for (zend_hash_internal_pointer_reset_ex(function_table, &position[1]);
  1240. zend_hash_get_current_data_ex(function_table, (void**)&brake, &position[1]) == SUCCESS;
  1241. zend_hash_move_forward_ex(function_table, &position[1])) {
  1242. phpdbg_writeln("#%d\t\t%s opline %ld%s",
  1243. brake->id, brake->func_name, brake->opline_num,
  1244. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1245. }
  1246. }
  1247. }
  1248. } break;
  1249. case PHPDBG_BREAK_FILE_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_OPLINE_BP)) {
  1250. HashPosition position[2];
  1251. HashTable *file_table;
  1252. char *file_name = NULL;
  1253. zend_uint file_len = 0;
  1254. zend_ulong file_idx = 0L;
  1255. phpdbg_writeln(SEPARATE);
  1256. phpdbg_writeln("File opline Breakpoints:");
  1257. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], &position[0]);
  1258. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], (void**) &file_table, &position[0]) == SUCCESS;
  1259. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], &position[0])) {
  1260. if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE],
  1261. &file_name, &file_len, &file_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
  1262. phpdbg_breakopline_t *brake;
  1263. for (zend_hash_internal_pointer_reset_ex(file_table, &position[1]);
  1264. zend_hash_get_current_data_ex(file_table, (void**)&brake, &position[1]) == SUCCESS;
  1265. zend_hash_move_forward_ex(file_table, &position[1])) {
  1266. phpdbg_writeln("#%d\t\t%s opline %ld%s",
  1267. brake->id, brake->class_name, brake->opline_num,
  1268. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1269. }
  1270. }
  1271. }
  1272. } break;
  1273. case PHPDBG_BREAK_COND: if ((PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)) {
  1274. HashPosition position;
  1275. phpdbg_breakcond_t *brake;
  1276. phpdbg_writeln(SEPARATE);
  1277. phpdbg_writeln("Conditional Breakpoints:");
  1278. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position);
  1279. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void**) &brake, &position) == SUCCESS;
  1280. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) {
  1281. if (brake->paramed) {
  1282. switch (brake->param.type) {
  1283. case STR_PARAM:
  1284. phpdbg_writeln("#%d\t\tat %s if %s%s",
  1285. brake->id,
  1286. brake->param.str,
  1287. brake->code,
  1288. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1289. break;
  1290. case NUMERIC_FUNCTION_PARAM:
  1291. phpdbg_writeln("#%d\t\tat %s#%ld if %s%s",
  1292. brake->id,
  1293. brake->param.str,
  1294. brake->param.num,
  1295. brake->code,
  1296. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1297. break;
  1298. case METHOD_PARAM:
  1299. phpdbg_writeln("#%d\t\tat %s::%s if %s%s",
  1300. brake->id,
  1301. brake->param.method.class,
  1302. brake->param.method.name,
  1303. brake->code,
  1304. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1305. break;
  1306. case NUMERIC_METHOD_PARAM:
  1307. phpdbg_writeln("#%d\t\tat %s::%s#%ld if %s%s",
  1308. brake->id,
  1309. brake->param.method.class,
  1310. brake->param.method.name,
  1311. brake->param.num,
  1312. brake->code,
  1313. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1314. break;
  1315. case FILE_PARAM:
  1316. phpdbg_writeln("#%d\t\tat %s:%lu if %s%s",
  1317. brake->id,
  1318. brake->param.file.name,
  1319. brake->param.file.line,
  1320. brake->code,
  1321. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1322. break;
  1323. case ADDR_PARAM:
  1324. phpdbg_writeln("#%d\t\tat #%lx if %s%s",
  1325. brake->id,
  1326. brake->param.addr,
  1327. brake->code,
  1328. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1329. break;
  1330. default:
  1331. phpdbg_error("Invalid parameter type for conditional breakpoint");
  1332. return;
  1333. }
  1334. } else {
  1335. phpdbg_writeln("#%d\t\tif %s%s",
  1336. brake->id, brake->code,
  1337. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1338. }
  1339. }
  1340. } break;
  1341. case PHPDBG_BREAK_OPCODE: if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) {
  1342. HashPosition position;
  1343. phpdbg_breakop_t *brake;
  1344. phpdbg_writeln(SEPARATE);
  1345. phpdbg_writeln("Opcode Breakpoints:");
  1346. for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position);
  1347. zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], (void**) &brake, &position) == SUCCESS;
  1348. zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position)) {
  1349. phpdbg_writeln("#%d\t\t%s%s",
  1350. brake->id, brake->name,
  1351. ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
  1352. }
  1353. } break;
  1354. }
  1355. } /* }}} */