Rev 4341 | Rev 4343 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4341 | Rev 4342 | ||
|---|---|---|---|
| Line 614... | Line 614... | ||
| 614 | /** Call function with zero parameters */ |
614 | /** Call function with zero parameters */ |
| 615 | int cmd_call0(cmd_arg_t *argv) |
615 | int cmd_call0(cmd_arg_t *argv) |
| 616 | { |
616 | { |
| 617 | uintptr_t symaddr; |
617 | uintptr_t symaddr; |
| 618 | char *symbol; |
618 | char *symbol; |
| 619 | unative_t (*f)(void); |
619 | unative_t (*fnc)(void); |
| 620 | #ifdef ia64 |
- | |
| 621 | struct { |
- | |
| 622 | unative_t f; |
- | |
| 623 | unative_t gp; |
620 | fncptr_t fptr; |
| 624 | } fptr; |
- | |
| 625 | #endif |
- | |
| 626 | 621 | ||
| 627 | symaddr = get_symbol_addr((char *) argv->buffer); |
622 | symaddr = get_symbol_addr((char *) argv->buffer); |
| 628 | if (!symaddr) |
623 | if (!symaddr) |
| 629 | printf("Symbol %s not found.\n", argv->buffer); |
624 | printf("Symbol %s not found.\n", argv->buffer); |
| 630 | else if (symaddr == (uintptr_t) -1) { |
625 | else if (symaddr == (uintptr_t) -1) { |
| 631 | symtab_print_search((char *) argv->buffer); |
626 | symtab_print_search((char *) argv->buffer); |
| 632 | printf("Duplicate symbol, be more specific.\n"); |
627 | printf("Duplicate symbol, be more specific.\n"); |
| 633 | } else { |
628 | } else { |
| 634 | symbol = get_symtab_entry(symaddr); |
629 | symbol = get_symtab_entry(symaddr); |
| - | 630 | fnc = (unative_t (*)(void)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call0); |
|
| 635 | printf("Calling %s() (%p)\n", symbol, symaddr); |
631 | printf("Calling %s() (%p)\n", symbol, symaddr); |
| 636 | #ifdef ia64 |
- | |
| 637 | fptr.f = symaddr; |
- | |
| 638 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
- | |
| 639 | f = (unative_t (*)(void)) &fptr; |
- | |
| 640 | #else |
- | |
| 641 | f = (unative_t (*)(void)) symaddr; |
- | |
| 642 | #endif |
- | |
| 643 | printf("Result: %#" PRIxn "\n", f()); |
632 | printf("Result: %#" PRIxn "\n", fnc()); |
| 644 | } |
633 | } |
| 645 | 634 | ||
| 646 | return 1; |
635 | return 1; |
| 647 | } |
636 | } |
| 648 | 637 | ||
| Line 678... | Line 667... | ||
| 678 | /** Call function with one parameter */ |
667 | /** Call function with one parameter */ |
| 679 | int cmd_call1(cmd_arg_t *argv) |
668 | int cmd_call1(cmd_arg_t *argv) |
| 680 | { |
669 | { |
| 681 | uintptr_t symaddr; |
670 | uintptr_t symaddr; |
| 682 | char *symbol; |
671 | char *symbol; |
| 683 | unative_t (*f)(unative_t,...); |
672 | unative_t (*fnc)(unative_t, ...); |
| 684 | unative_t arg1 = argv[1].intval; |
673 | unative_t arg1 = argv[1].intval; |
| 685 | #ifdef ia64 |
- | |
| 686 | struct { |
- | |
| 687 | unative_t f; |
- | |
| 688 | unative_t gp; |
674 | fncptr_t fptr; |
| 689 | } fptr; |
- | |
| 690 | #endif |
- | |
| 691 | 675 | ||
| 692 | symaddr = get_symbol_addr((char *) argv->buffer); |
676 | symaddr = get_symbol_addr((char *) argv->buffer); |
| 693 | if (!symaddr) |
677 | if (!symaddr) |
| 694 | printf("Symbol %s not found.\n", argv->buffer); |
678 | printf("Symbol %s not found.\n", argv->buffer); |
| 695 | else if (symaddr == (uintptr_t) -1) { |
679 | else if (symaddr == (uintptr_t) -1) { |
| 696 | symtab_print_search((char *) argv->buffer); |
680 | symtab_print_search((char *) argv->buffer); |
| 697 | printf("Duplicate symbol, be more specific.\n"); |
681 | printf("Duplicate symbol, be more specific.\n"); |
| 698 | } else { |
682 | } else { |
| 699 | symbol = get_symtab_entry(symaddr); |
683 | symbol = get_symtab_entry(symaddr); |
| 700 | - | ||
| - | 684 | fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1); |
|
| 701 | printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); |
685 | printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); |
| 702 | #ifdef ia64 |
- | |
| 703 | fptr.f = symaddr; |
- | |
| 704 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
- | |
| 705 | f = (unative_t (*)(unative_t,...)) &fptr; |
- | |
| 706 | #else |
- | |
| 707 | f = (unative_t (*)(unative_t,...)) symaddr; |
- | |
| 708 | #endif |
- | |
| 709 | printf("Result: %#" PRIxn "\n", f(arg1)); |
686 | printf("Result: %#" PRIxn "\n", fnc(arg1)); |
| 710 | } |
687 | } |
| 711 | 688 | ||
| 712 | return 1; |
689 | return 1; |
| 713 | } |
690 | } |
| 714 | 691 | ||
| 715 | /** Call function with two parameters */ |
692 | /** Call function with two parameters */ |
| 716 | int cmd_call2(cmd_arg_t *argv) |
693 | int cmd_call2(cmd_arg_t *argv) |
| 717 | { |
694 | { |
| 718 | uintptr_t symaddr; |
695 | uintptr_t symaddr; |
| 719 | char *symbol; |
696 | char *symbol; |
| 720 | unative_t (*f)(unative_t,unative_t,...); |
697 | unative_t (*fnc)(unative_t, unative_t, ...); |
| 721 | unative_t arg1 = argv[1].intval; |
698 | unative_t arg1 = argv[1].intval; |
| 722 | unative_t arg2 = argv[2].intval; |
699 | unative_t arg2 = argv[2].intval; |
| 723 | #ifdef ia64 |
- | |
| 724 | struct { |
- | |
| 725 | unative_t f; |
- | |
| 726 | unative_t gp; |
700 | fncptr_t fptr; |
| 727 | }fptr; |
- | |
| 728 | #endif |
- | |
| 729 | 701 | ||
| 730 | symaddr = get_symbol_addr((char *) argv->buffer); |
702 | symaddr = get_symbol_addr((char *) argv->buffer); |
| 731 | if (!symaddr) |
703 | if (!symaddr) |
| 732 | printf("Symbol %s not found.\n", argv->buffer); |
704 | printf("Symbol %s not found.\n", argv->buffer); |
| 733 | else if (symaddr == (uintptr_t) -1) { |
705 | else if (symaddr == (uintptr_t) -1) { |
| 734 | symtab_print_search((char *) argv->buffer); |
706 | symtab_print_search((char *) argv->buffer); |
| 735 | printf("Duplicate symbol, be more specific.\n"); |
707 | printf("Duplicate symbol, be more specific.\n"); |
| 736 | } else { |
708 | } else { |
| 737 | symbol = get_symtab_entry(symaddr); |
709 | symbol = get_symtab_entry(symaddr); |
| - | 710 | fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2); |
|
| 738 | printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
711 | printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
| 739 | arg1, arg2, symaddr, symbol); |
712 | arg1, arg2, symaddr, symbol); |
| 740 | #ifdef ia64 |
- | |
| 741 | fptr.f = symaddr; |
- | |
| 742 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
- | |
| 743 | f = (unative_t (*)(unative_t,unative_t,...)) &fptr; |
- | |
| 744 | #else |
- | |
| 745 | f = (unative_t (*)(unative_t,unative_t,...)) symaddr; |
- | |
| 746 | #endif |
- | |
| 747 | printf("Result: %#" PRIxn "\n", f(arg1, arg2)); |
713 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2)); |
| 748 | } |
714 | } |
| 749 | 715 | ||
| 750 | return 1; |
716 | return 1; |
| 751 | } |
717 | } |
| 752 | 718 | ||
| 753 | /** Call function with three parameters */ |
719 | /** Call function with three parameters */ |
| 754 | int cmd_call3(cmd_arg_t *argv) |
720 | int cmd_call3(cmd_arg_t *argv) |
| 755 | { |
721 | { |
| 756 | uintptr_t symaddr; |
722 | uintptr_t symaddr; |
| 757 | char *symbol; |
723 | char *symbol; |
| 758 | unative_t (*f)(unative_t,unative_t,unative_t,...); |
724 | unative_t (*fnc)(unative_t, unative_t, unative_t, ...); |
| 759 | unative_t arg1 = argv[1].intval; |
725 | unative_t arg1 = argv[1].intval; |
| 760 | unative_t arg2 = argv[2].intval; |
726 | unative_t arg2 = argv[2].intval; |
| 761 | unative_t arg3 = argv[3].intval; |
727 | unative_t arg3 = argv[3].intval; |
| 762 | #ifdef ia64 |
- | |
| 763 | struct { |
- | |
| 764 | unative_t f; |
- | |
| 765 | unative_t gp; |
728 | fncptr_t fptr; |
| 766 | }fptr; |
- | |
| 767 | #endif |
- | |
| 768 | 729 | ||
| 769 | symaddr = get_symbol_addr((char *) argv->buffer); |
730 | symaddr = get_symbol_addr((char *) argv->buffer); |
| 770 | if (!symaddr) |
731 | if (!symaddr) |
| 771 | printf("Symbol %s not found.\n", argv->buffer); |
732 | printf("Symbol %s not found.\n", argv->buffer); |
| 772 | else if (symaddr == (uintptr_t) -1) { |
733 | else if (symaddr == (uintptr_t) -1) { |
| 773 | symtab_print_search((char *) argv->buffer); |
734 | symtab_print_search((char *) argv->buffer); |
| 774 | printf("Duplicate symbol, be more specific.\n"); |
735 | printf("Duplicate symbol, be more specific.\n"); |
| 775 | } else { |
736 | } else { |
| 776 | symbol = get_symtab_entry(symaddr); |
737 | symbol = get_symtab_entry(symaddr); |
| - | 738 | fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3); |
|
| 777 | printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
739 | printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
| 778 | arg1, arg2, arg3, symaddr, symbol); |
740 | arg1, arg2, arg3, symaddr, symbol); |
| 779 | #ifdef ia64 |
- | |
| 780 | fptr.f = symaddr; |
- | |
| 781 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
- | |
| 782 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr; |
- | |
| 783 | #else |
- | |
| 784 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr; |
- | |
| 785 | #endif |
- | |
| 786 | printf("Result: %#" PRIxn "\n", f(arg1, arg2, arg3)); |
741 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3)); |
| 787 | } |
742 | } |
| 788 | 743 | ||
| 789 | return 1; |
744 | return 1; |
| 790 | } |
745 | } |
| 791 | 746 | ||
| Line 994... | Line 949... | ||
| 994 | int cmd_tests(cmd_arg_t *argv) |
949 | int cmd_tests(cmd_arg_t *argv) |
| 995 | { |
950 | { |
| 996 | test_t *test; |
951 | test_t *test; |
| 997 | 952 | ||
| 998 | for (test = tests; test->name != NULL; test++) |
953 | for (test = tests; test->name != NULL; test++) |
| 999 | printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
954 | printf("%-10s %s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
| 1000 | 955 | ||
| 1001 | printf("*\t\tRun all safe tests\n"); |
956 | printf("%-10s Run all safe tests\n", "*"); |
| 1002 | return 1; |
957 | return 1; |
| 1003 | } |
958 | } |
| 1004 | 959 | ||
| 1005 | static bool run_test(const test_t *test) |
960 | static bool run_test(const test_t *test) |
| 1006 | { |
961 | { |