dumpmyself.c revision 115013
1/*
2 * Copyright (c) 2002,2003 Hewlett-Packard Company
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include "uwx.h"
24#include "uwx_self.h"
25
26struct uwx_env *uenv;
27struct uwx_self_info *cbinfo;
28
29extern int uwx_get_frame_info(struct uwx_env *uenv);
30
31extern void dump_context(uint64_t *context);
32
33int main(int argc, char **argv)
34{
35    int status;
36    unsigned int *wp;
37    uenv = uwx_init();
38    printf("uwx_init returned %08x\n", uenv);
39    cbinfo = uwx_self_init_info(uenv);
40    status = uwx_register_callbacks(
41		uenv,
42		(intptr_t)cbinfo,
43		uwx_self_copyin,
44		uwx_self_lookupip);
45    printf("uwx_register_callbacks returned %d\n", status);
46    uwx_self_init_context(uenv);
47    printf("In main():\n");
48    dump_context((uint64_t *)uenv);
49    (void) f1();
50    uwx_free(uenv);
51    return 0;
52}
53
54int f1(void)
55{
56    uwx_self_init_context(uenv);
57    printf("In f1():\n");
58    dump_context((uint64_t *)uenv);
59    return f2();
60}
61
62int f2(void)
63{
64    uwx_self_init_context(uenv);
65    printf("In f2():\n");
66    dump_context((uint64_t *)uenv);
67    return f3();
68}
69
70int f3(void)
71{
72    uwx_self_init_context(uenv);
73    printf("In f3():\n");
74    dump_context((uint64_t *)uenv);
75    return f4();
76}
77
78int f4(void)
79{
80    int status;
81    int foo[10];
82    f5(foo);
83    uwx_self_init_context(uenv);
84    printf("In f4():\n");
85    dump_context((uint64_t *)uenv);
86    for (;;) {
87	status = uwx_step(uenv);
88	printf("uwx_step returned %d\n", status);
89	if (status != UWX_OK)
90	    break;
91	printf("After step:\n");
92	dump_context((uint64_t *)uenv);
93    }
94    return 0;
95}
96
97int f5(int *foo)
98{
99    foo[0] = 0;
100    return 0;
101}
102