phpdbg_bp.c 53 KB

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