Hi Aubrey, Aubrey Li wrote: > On 8/3/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >> Hi Aubrey, >> Aubrey Li wrote: >> >> > Here, global_structure is defined in the kernel head file, and this > file depends on another bunch of head files, How could access it in a > standalone program? > You just need to include the header files (and any header files that these header files depend on, and so on). You can do this by trial and error, or you can look at the header files that an application is using to do the same thing (such as mdb source code). Header files should not be adding space to your executable, i.e., they should only contain definitions and data types, not instances. You may need to use "-D_KERNEL" when building the application. > >> ... >> >> Instead of printing the global address from the driver, you could >> instead add an ioctl to get the address, and then >> have you app open the device, ioctl to get the address, and then do the >> above. Really, if all you want to do >> is print the structure from user space, it would be much simpler to use >> mdb to do this. mdb is in user space. >> > > Yes, mdb can dump the root node of the structure, while the whole > structure is a tree, I need the info of every nodes. So, mdb is not > enough. > > Gavin mentioned the avl walker if the tree is an AVL tree. If the tree is not an AVL tree, you'll need to write a walker as he says. There is some simple example dcmd and walker in /usr/demo/mdb. If the tree is actually a linked list, there is also the "list" comand in mdb.
address::list type member_to_next_element | ::print type where type is the data structure, and member_to_next_element is the name of the field that points to the next element. All of this assumes that the structure is defined in CTF. If it's part of the kernel as shipped, the CTF will be there. If the structure is declared in your driver, you will need to figure out how to add the CTF. The standard response to "how do I do that?" is "look at the source". Does anyone know if this will ever get documented? Is it not documented because it may change, or is it because there are not enough resources? >> Also, the driver can access global variables. If you are getting an >> "undefined symbol" when you try to load the >> > > >> driver, it sounds like the global symbol is defined in some other module >> (driver), and the module/driver where the >> symbol is defined is not loaded when the driver is being added. When >> > > Firstly, The command "global_struct=X" can print the address of this variable. > I think that means is already loaded. Then I run "add_drv" command to > add my driver. > It still reports "undefined symbol". > When it says "undefined symbol", is the undefined symbol the data structure you are interested in, or is it something else? > >> you build the driver, use: >> $ ld -r -dy -N drv/foo mydriver.o -o mydriver >> >> to specify that your driver (mydriver) has a dependency on the "foo" >> module (where "foo" defines the global). >> > > I'll have a try, thanks for your help, ;-) > > -Aubrey > > good luck, max _______________________________________________ opensolaris-code mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/opensolaris-code
