| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "../../src/commands.h" |
| 28 |
#include "../../src/file.h" |
| 29 |
#include "../../src/implicit.h" |
| 30 |
#include "../../src/print.h" |
| 31 |
#include "../../src/main.h" |
| 32 |
#include "../../src/rule.h" |
| 33 |
#include "../../src/debug.h" |
| 34 |
#include "../../src/vpath.h" |
| 35 |
#include "../break.h" |
| 36 |
#include "../fns.h" |
| 37 |
#include "../info.h" |
| 38 |
#include "../msg.h" |
| 39 |
#include "../stack.h" |
| 40 |
#include "../file2line.h" |
| 41 |
|
| 42 |
const char *WARRANTY = |
| 43 |
" NO WARRANTY\n" |
| 44 |
"\n" |
| 45 |
" 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n" |
| 46 |
"FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n" |
| 47 |
"OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n" |
| 48 |
"PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n" |
| 49 |
"OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n" |
| 50 |
"MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n" |
| 51 |
"TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n" |
| 52 |
"PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n" |
| 53 |
"REPAIR OR CORRECTION.\n" |
| 54 |
"\n" |
| 55 |
" 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n" |
| 56 |
"WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n" |
| 57 |
"REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n" |
| 58 |
"INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n" |
| 59 |
"OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n" |
| 60 |
"TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n" |
| 61 |
"YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n" |
| 62 |
"PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n" |
| 63 |
"POSSIBILITY OF SUCH DAMAGES.\n"; |
| 64 |
|
| 65 |
#include "../subcmd.h" |
| 66 |
|
| 67 |
subcommand_var_info_t info_subcommands[] = { |
| 68 |
{ "break", |
| 69 |
"Show list of target breakpoints", |
| 70 |
"\n\nShow list of target breakpoints.", |
| 71 |
NULL, false, |
| 72 |
1}, |
| 73 |
{ "line", |
| 74 |
"Show where we are currently stopped", |
| 75 |
"\n\nShow line and Makefile name of where we are currently stopped.", |
| 76 |
NULL, false, |
| 77 |
2}, |
| 78 |
{ "lines", |
| 79 |
"Show possible breakpoint lines for all targets", |
| 80 |
"\n\nShow possible breakpoint lines for all targets.", |
| 81 |
NULL, false, |
| 82 |
2}, |
| 83 |
{ "locals", |
| 84 |
"Show target local variables and their values", |
| 85 |
"\n\nShow target local variables and their values.", |
| 86 |
NULL, false, |
| 87 |
2}, |
| 88 |
{ "files", |
| 89 |
"Show read-in Makefiles", |
| 90 |
"\n\nShow read-in Makefiles. The last is the one initially named.", |
| 91 |
NULL, false, |
| 92 |
2}, |
| 93 |
{ "frame", |
| 94 |
"Show target-stack frame", |
| 95 |
"\n\nShow target-stack frame.", |
| 96 |
NULL, false, |
| 97 |
2}, |
| 98 |
{ "rules", |
| 99 |
"Show implicit or pattern rules", |
| 100 |
" [VERBOSE]\n\n" |
| 101 |
"Show implicit or pattern rules. Add VERBOSE if you want more info." |
| 102 |
, |
| 103 |
NULL, false, |
| 104 |
1}, |
| 105 |
{ "program", |
| 106 |
"Show program information and why we are stopped", |
| 107 |
"\n\nShow program information and why we are stopped.", |
| 108 |
NULL, false, |
| 109 |
1}, |
| 110 |
{ "target", |
| 111 |
"Same as 'target'", |
| 112 |
"\n\nShow specific target information. See 'help target'.", |
| 113 |
NULL, false, |
| 114 |
1}, |
| 115 |
{ "targets", |
| 116 |
"Show a list of target names and file locations", |
| 117 |
" [NAMES|POSITIONS|TASKS|ALL]\n\n" |
| 118 |
"Show the explicitly-named targets found in read Makefiles.\n" |
| 119 |
"Suboptions are as follows:\n" |
| 120 |
" NAMES -- shows target names,\n" |
| 121 |
" POSITIONS -- shows the location in the Makefile\n" |
| 122 |
" ALL -- shows names and location\n" |
| 123 |
" TASKS -- shows target name if it has commands associated with it\n" |
| 124 |
"\n" |
| 125 |
"The default is ALL.", |
| 126 |
NULL, false, |
| 127 |
7}, |
| 128 |
{ "tasks", |
| 129 |
"Show a list of tasks and their descriptions", |
| 130 |
"\n", |
| 131 |
NULL, false, |
| 132 |
3}, |
| 133 |
{ "variables", |
| 134 |
"Show all GNU Make variables", |
| 135 |
"\n\nShow all GNU Make variables.", |
| 136 |
NULL, false, |
| 137 |
2}, |
| 138 |
{ "warranty", |
| 139 |
"Various kinds of warranty you do not have", |
| 140 |
"\n\nVarious kinds of warranty you do not have.", |
| 141 |
NULL, false, |
| 142 |
1}, |
| 143 |
{ NULL, NULL, NULL, NULL, false, 0} |
| 144 |
}; |
| 145 |
|
| 146 |
|
| 147 |
static void |
| 148 |
dbg_cmd_info_target_entry (const file_t *p_target, |
| 149 |
info_target_output_mask_t output_mask) |
| 150 |
{ |
| 151 |
const gmk_floc *p_floc = &p_target->floc; |
| 152 |
if (p_floc) { |
| 153 |
if ((p_floc->filenm) && (output_mask & INFO_TARGET_POSITION)) { |
| 154 |
printf("%s:%lu", p_floc->filenm, p_floc->lineno); |
| 155 |
if (output_mask & INFO_TARGET_NAME) |
| 156 |
printf(":\n"); |
| 157 |
else |
| 158 |
printf("\n"); |
| 159 |
} |
| 160 |
} |
| 161 |
if (output_mask & INFO_TARGET_NAME) { |
| 162 |
printf("\t%s", p_target->name); |
| 163 |
if (p_target->description) |
| 164 |
printf("\t# %s", p_target->description); |
| 165 |
printf("\n"); |
| 166 |
} else if |
| 167 |
( (output_mask & INFO_TARGET_TASKS |
| 168 |
&& (p_target->cmds || p_target->phony) |
| 169 |
&& p_floc->filenm) |
| 170 |
|| (output_mask & INFO_TARGET_NAME) ) { |
| 171 |
if (p_target->description) { |
| 172 |
printf("%s", p_target->name); |
| 173 |
printf("\t# %s\n", p_target->description); |
| 174 |
} else if (!(output_mask & INFO_TARGET_TASK_COMMENT)) { |
| 175 |
printf("%s\n", p_target->name); |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
int |
| 181 |
dbg_target_compare(const void *p1, const void *p2) |
| 182 |
{ |
| 183 |
const struct file *p_target1 = *(const file_t **) p1; |
| 184 |
const struct file *p_target2 = *(const file_t **) p2; |
| 185 |
return strcmp(p_target1->name, p_target2->name); |
| 186 |
} |
| 187 |
|
| 188 |
void |
| 189 |
dbg_cmd_info_targets(info_target_output_mask_t output_mask) |
| 190 |
{ |
| 191 |
struct file **file_slot_0 = (struct file **) hash_dump (&files, 0, |
| 192 |
dbg_target_compare); |
| 193 |
struct file **file_end = file_slot_0 + files.ht_fill; |
| 194 |
struct file **pp_file_slot; |
| 195 |
struct file *p_target; |
| 196 |
|
| 197 |
for (pp_file_slot = file_slot_0; pp_file_slot < file_end; pp_file_slot++) { |
| 198 |
if ((p_target = *pp_file_slot) != NULL) |
| 199 |
dbg_cmd_info_target_entry(p_target, output_mask); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
void |
| 204 |
dbg_cmd_info_tasks() |
| 205 |
{ |
| 206 |
struct file **file_slot_0 = (struct file **) hash_dump (&files, 0, |
| 207 |
dbg_target_compare); |
| 208 |
struct file **file_end = file_slot_0 + files.ht_fill; |
| 209 |
struct file **pp_file_slot; |
| 210 |
struct file *p_target; |
| 211 |
|
| 212 |
for (pp_file_slot = file_slot_0; pp_file_slot < file_end; pp_file_slot++) { |
| 213 |
if ((p_target = *pp_file_slot) != NULL && p_target->description) { |
| 214 |
printf("%-20s %s\n", p_target->name, p_target->description); |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
void |
| 221 |
dbg_cmd_info_line() |
| 222 |
{ |
| 223 |
if (p_stack_top && p_stack_top->p_target && |
| 224 |
p_stack_top->p_target->floc.filenm) { |
| 225 |
const gmk_floc *p_floc = &p_stack_top->p_target->floc; |
| 226 |
if (!basename_filenames && strlen(p_floc->filenm) |
| 227 |
&& p_floc->filenm[0] != '/') |
| 228 |
dbg_msg("Line %lu of \"%s/%s\"", |
| 229 |
p_floc->lineno, starting_directory, |
| 230 |
p_floc->filenm); |
| 231 |
else |
| 232 |
dbg_msg("Line %lu of \"%s\"", p_floc->lineno, p_floc->filenm); |
| 233 |
} else { |
| 234 |
dbg_msg("No line number info recorded.\n"); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
void |
| 239 |
dbg_cmd_info_program() |
| 240 |
{ |
| 241 |
printf(_("Starting directory `%s'\n"), starting_directory); |
| 242 |
printf(_("Program invocation:\n")); |
| 243 |
printf("\t"); |
| 244 |
dbg_print_invocation(); |
| 245 |
printf(_("Recursion level: %u\n"), makelevel); |
| 246 |
dbg_cmd_info_line(); |
| 247 |
switch (last_stop_reason) |
| 248 |
{ |
| 249 |
case DEBUG_BRKPT_AFTER_CMD: |
| 250 |
printf(_("Program is stopped after running rule command(s).\n")); |
| 251 |
break; |
| 252 |
case DEBUG_BRKPT_BEFORE_PREREQ: |
| 253 |
printf(_("Program stopped before rule-prequisite checking.\n")); |
| 254 |
break; |
| 255 |
case DEBUG_BRKPT_AFTER_PREREQ: |
| 256 |
printf(_("Program is stopped after rule-prequisite checking.\n")); |
| 257 |
break; |
| 258 |
case DEBUG_GOAL_UPDATED_HIT: |
| 259 |
printf(_("Program stopped for updating a goal.\n")); |
| 260 |
printf("\n"); |
| 261 |
break; |
| 262 |
case DEBUG_READ_HIT: |
| 263 |
printf(_("Program stopped for reading a file.\n")); |
| 264 |
printf("\n"); |
| 265 |
break; |
| 266 |
case DEBUG_ERROR_HIT: |
| 267 |
printf(_("Program stopped after an error encountered.\n")); |
| 268 |
printf("\n"); |
| 269 |
break; |
| 270 |
case DEBUG_STEP_HIT: |
| 271 |
printf(_("Program stopped in stepping.\n")); |
| 272 |
printf("\n"); |
| 273 |
break; |
| 274 |
case DEBUG_STEP_COMMAND: |
| 275 |
printf(_("Program stopped in stepping before running rule command(s).\n")); |
| 276 |
printf("\n"); |
| 277 |
break; |
| 278 |
case DEBUG_EXPLICIT_CALL: |
| 279 |
printf(_("Program stopped from explicit debugger function call.\n")); |
| 280 |
printf("\n"); |
| 281 |
break; |
| 282 |
case DEBUG_NOT_GIVEN: |
| 283 |
printf(_("Reason not given.\n")); |
| 284 |
break; |
| 285 |
case DEBUG_STACK_CHANGING: |
| 286 |
|
| 287 |
break; |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
debug_return_t |
| 294 |
dbg_cmd_info(char *psz_args) |
| 295 |
{ |
| 296 |
if (!psz_args || 0==strlen(psz_args)) { |
| 297 |
unsigned int i; |
| 298 |
for (i = 0; info_subcommands[i].name; i++) { |
| 299 |
dbg_help_subcmd_entry("info", "%-10s -- %s", |
| 300 |
&(info_subcommands[i]), false); |
| 301 |
} |
| 302 |
return debug_readloop; |
| 303 |
} else { |
| 304 |
char *psz_subcmd = get_word(&psz_args); |
| 305 |
if (0 == strcmp(psz_subcmd, "lines")) { |
| 306 |
file2lines_dump(); |
| 307 |
} else if (is_abbrev_of (psz_subcmd, "line", 2)) { |
| 308 |
dbg_cmd_info_line(); |
| 309 |
} else if (is_abbrev_of (psz_subcmd, "locals", 2)) { |
| 310 |
const char *psz_target = NULL; |
| 311 |
char *psz_subcmds = NULL; |
| 312 |
file_t *p_target = get_target(&psz_subcmds, &psz_target); |
| 313 |
|
| 314 |
if (p_target) { |
| 315 |
if (!p_target->variables) { |
| 316 |
initialize_file_variables (p_target, 0); |
| 317 |
set_file_variables (p_target); |
| 318 |
if (!p_target->variables) { |
| 319 |
printf("Can't get variable information for target %s\n", |
| 320 |
psz_target); |
| 321 |
return debug_readloop; |
| 322 |
} |
| 323 |
} |
| 324 |
} else { |
| 325 |
dbg_errmsg("No target information for %s.", psz_target); |
| 326 |
return debug_cmd_error; |
| 327 |
} |
| 328 |
hash_map_arg (&p_target->variables->set->table, |
| 329 |
print_variable_info, NULL); |
| 330 |
} else if (is_abbrev_of (psz_subcmd, "breakpoints", 1)) { |
| 331 |
list_breakpoints(); |
| 332 |
} else if (is_abbrev_of (psz_subcmd, "makefiles", 1) || |
| 333 |
is_abbrev_of (psz_subcmd, "files", 2)) { |
| 334 |
if (0 == strlen(psz_args)) |
| 335 |
print_read_makefiles(NULL); |
| 336 |
else { |
| 337 |
if (!print_read_makefiles(psz_args)) |
| 338 |
dbg_errmsg("File %s not in list of read-in files.", psz_args); |
| 339 |
} |
| 340 |
} else if (is_abbrev_of (psz_subcmd, "frame", 2)) { |
| 341 |
dbg_cmd_where(psz_args); |
| 342 |
} else if (is_abbrev_of (psz_subcmd, "program", 1)) { |
| 343 |
dbg_cmd_info_program(); |
| 344 |
} else if (is_abbrev_of (psz_subcmd, "rules", 1)) { |
| 345 |
if (0 == strlen(psz_args)) |
| 346 |
print_rule_data_base (false); |
| 347 |
else if (0 == strcmp(psz_args, "verbose")) |
| 348 |
print_rule_data_base (true); |
| 349 |
else |
| 350 |
{ |
| 351 |
rule_t *r = find_rule(psz_args); |
| 352 |
if (r) |
| 353 |
print_rule(r, true); |
| 354 |
else |
| 355 |
dbg_errmsg(_("Rule %s not found."), psz_args); |
| 356 |
} |
| 357 |
} else if (is_abbrev_of (psz_subcmd, "stack", 1)) { |
| 358 |
print_target_stack(p_stack_top, i_stack_pos, MAX_STACK_SHOW); |
| 359 |
} else if (0 == strcmp(psz_subcmd, "targets")) { |
| 360 |
|
| 361 |
info_target_output_mask_t output_type; |
| 362 |
if (0 == strlen(psz_args)) |
| 363 |
output_type = INFO_TARGET_POSITION_AND_NAME; |
| 364 |
else if (is_abbrev_of (psz_args, "all", 1)) |
| 365 |
output_type = INFO_TARGET_POSITION_AND_NAME; |
| 366 |
else if (is_abbrev_of (psz_args, "positions", 1)) |
| 367 |
output_type = INFO_TARGET_POSITION; |
| 368 |
else if (is_abbrev_of (psz_args, "names", 1)) |
| 369 |
output_type = INFO_TARGET_NAME; |
| 370 |
else if (is_abbrev_of (psz_args, "tasks", 1)) |
| 371 |
output_type = INFO_TARGET_TASKS; |
| 372 |
else { |
| 373 |
printf("Expecting 'all', 'positions', 'names', 'tasks', or nothing; got %s.\n", |
| 374 |
psz_args); |
| 375 |
return debug_cmd_error; |
| 376 |
} |
| 377 |
dbg_cmd_info_targets(output_type); |
| 378 |
|
| 379 |
} else if (0 == strcmp(psz_subcmd, "tasks")) { |
| 380 |
dbg_cmd_info_tasks(); |
| 381 |
|
| 382 |
} else if (is_abbrev_of (psz_subcmd, "target", 1)) { |
| 383 |
if (0 == strlen(psz_args)) { |
| 384 |
if (p_stack_top && p_stack_top->p_target && |
| 385 |
p_stack_top->p_target->name) |
| 386 |
printf("target: %s\n", p_stack_top->p_target->name); |
| 387 |
else |
| 388 |
{ |
| 389 |
printf("target unknown\n"); |
| 390 |
} |
| 391 |
} |
| 392 |
else |
| 393 |
dbg_cmd_target(psz_args); |
| 394 |
|
| 395 |
} else if (is_abbrev_of (psz_subcmd, "variables", 1)) { |
| 396 |
print_variable_data_base(); |
| 397 |
} else if (is_abbrev_of (psz_subcmd, "vpath", 1)) { |
| 398 |
print_vpath_data_base (); |
| 399 |
} else if (is_abbrev_of (psz_subcmd, "warranty", 1)) { |
| 400 |
printf("%s", WARRANTY); |
| 401 |
} else { |
| 402 |
dbg_errmsg(_("Undefined command \"%s\". Try \"help info\"."), |
| 403 |
psz_subcmd); |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
return debug_readloop; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|