Skip to content

Commit 0a2f837

Browse files
committed
Add an mdb example, and fixup mdb Makefiles
1 parent 0543bac commit 0a2f837

File tree

9 files changed

+180
-5
lines changed

9 files changed

+180
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Note: this does not try to ignore all files in a fully built workspace.
33
# Rather, you are expected to "make clobber" before running "git status".
44
.make.state*
5+
/packages
56
/proto
67
/usr/src/TAGS
78
/usr/src/cscope.*

usr/src/cmd/mdb/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include $(SRC)/Makefile.master
2929
.KEEP_STATE:
3030

3131
sparc_SUBDIRS =
32-
i386_SUBDIRS =
32+
i386_SUBDIRS = foo
3333

3434
SUBDIRS = $($(MACH)_SUBDIRS)
3535
TARGET =

usr/src/cmd/mdb/Makefile.module

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ $(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
179179
$(KMDB_FPTEST_CMD)
180180
$(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS)
181181
$(POST_PROCESS)
182-
$(SETDYNFLAG) -f DF_1_NOKSYMS $@
182+
$(SETDYNFLAG) $@
183183

184184
linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
185185
$(KMDB_LINKTEST)

usr/src/cmd/mdb/Makefile.tools

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626

2727
TOOLSDIR = $(SRC)/cmd/mdb/tools
2828

29-
#SETDYNFLAG = $(TOOLSDIR)/setdynflag/$(MACH)/setdynflag
30-
SETDYNFLAG = true TODO
31-
#FINDFP = $(TOOLSDIR)/findfp/$(MACH)/findfp
29+
# Set the dynamic.flags1 field to: [ NOKSYMS EDITED ]
30+
# You can inspect it with: elfedit -e "dyn:flags1" file
31+
SETDYNFLAG = elfedit -e "dyn:flags1 0x280000"
32+
33+
# FINDFP is only used on sparc anyway.
34+
# It's probably better to use compiler options to avoid FP instructions,
35+
# i.e. gcc -msoft-float -mno-sse ...
3236
FINDFP = true TODO

usr/src/cmd/mdb/foo/Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# This file and its contents are supplied under the terms of the
3+
# Common Development and Distribution License ("CDDL"), version 1.0.
4+
# You may only use this file in accordance with the terms of version
5+
# 1.0 of the CDDL.
6+
#
7+
# A full copy of the text of the CDDL should have accompanied this
8+
# source. A copy of the CDDL is also available via the Internet at
9+
# http://www.illumos.org/license/CDDL.
10+
#
11+
12+
#
13+
# Copyright 2016 Gordon Ross <[email protected]>
14+
#
15+
16+
include $(SRC)/Makefile.master
17+
SUBDIRS = ia32
18+
$(BUILD64)SUBDIRS += $(MACH64)
19+
include ../Makefile.subdirs

usr/src/cmd/mdb/foo/amd64/Makefile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This file and its contents are supplied under the terms of the
3+
# Common Development and Distribution License ("CDDL"), version 1.0.
4+
# You may only use this file in accordance with the terms of version
5+
# 1.0 of the CDDL.
6+
#
7+
# A full copy of the text of the CDDL should have accompanied this
8+
# source. A copy of the CDDL is also available via the Internet at
9+
# http://www.illumos.org/license/CDDL.
10+
#
11+
12+
#
13+
# Copyright 2016 Gordon Ross <[email protected]>
14+
#
15+
16+
MODULE = foo.so
17+
MDBTGT = kvm
18+
19+
MODSRCS = foo.c
20+
21+
include ../../../Makefile.cmd
22+
include ../../../Makefile.cmd.64
23+
include ../../Makefile.amd64
24+
include ../../Makefile.module
25+
26+
CPPFLAGS += -I$(SRC)/uts/common

usr/src/cmd/mdb/foo/foo.c

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* This file and its contents are supplied under the terms of the
3+
* Common Development and Distribution License ("CDDL"), version 1.0.
4+
* You may only use this file in accordance with the terms of version
5+
* 1.0 of the CDDL.
6+
*
7+
* A full copy of the text of the CDDL should have accompanied this
8+
* source. A copy of the CDDL is also available via the Internet at
9+
* http://www.illumos.org/license/CDDL.
10+
*/
11+
12+
/*
13+
* Copyright 2016 Gordon Ross <[email protected]>
14+
*/
15+
16+
/*
17+
* Example mdb module: foo
18+
*/
19+
#include <sys/mdb_modapi.h>
20+
#include <sys/foo.h>
21+
22+
/*
23+
* One would be correct to observe that a dcmd is unnecessary for
24+
* just printing a variable with mdb. This is just an example,
25+
* where a more real-world case would print something larger and
26+
* more complex than a foocnt_t.
27+
*/
28+
29+
void
30+
foo_cnt_help(void)
31+
{
32+
mdb_printf("Print device ID information of Intel graphics card.\n");
33+
}
34+
35+
/* ARGSUSED */
36+
static int
37+
foo_cnt_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
38+
{
39+
GElf_Sym sym;
40+
foocnt_t count;
41+
42+
/* Does not take an address. */
43+
if (flags & DCMD_ADDRSPEC)
44+
return (DCMD_USAGE);
45+
46+
/* Locate the foo_count variable */
47+
if (mdb_lookup_by_obj("foo", "foo_count", &sym)) {
48+
mdb_warn("failed to lookup `foo_count'\n");
49+
return (DCMD_ERR);
50+
}
51+
addr = (uintptr_t)sym.st_value;
52+
53+
if (mdb_vread(&count, sizeof (count), addr) == -1) {
54+
mdb_warn("failed to read foo_count at %p", addr);
55+
return (DCMD_ERR);
56+
}
57+
58+
mdb_printf("foo_count = %d\n", count);
59+
60+
return (DCMD_OK);
61+
}
62+
63+
64+
/*
65+
* MDB module linkage information:
66+
*
67+
* We declare a list of structures describing our dcmds, a list of structures
68+
* describing our walkers, and a function named _mdb_init to return a pointer
69+
* to our module information.
70+
*/
71+
72+
static const mdb_dcmd_t dcmds[] = {
73+
{
74+
"foo_cnt",
75+
"?",
76+
"get foo_count",
77+
foo_cnt_dcmd,
78+
foo_cnt_help
79+
},
80+
{ NULL }
81+
};
82+
83+
static const mdb_walker_t walkers[] = {
84+
/* none */
85+
{ NULL }
86+
};
87+
88+
static const mdb_modinfo_t modinfo = {
89+
MDB_API_VERSION, dcmds, walkers
90+
};
91+
92+
const mdb_modinfo_t *
93+
_mdb_init(void)
94+
{
95+
return (&modinfo);
96+
}

usr/src/cmd/mdb/foo/ia32/Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# This file and its contents are supplied under the terms of the
3+
# Common Development and Distribution License ("CDDL"), version 1.0.
4+
# You may only use this file in accordance with the terms of version
5+
# 1.0 of the CDDL.
6+
#
7+
# A full copy of the text of the CDDL should have accompanied this
8+
# source. A copy of the CDDL is also available via the Internet at
9+
# http://www.illumos.org/license/CDDL.
10+
#
11+
12+
#
13+
# Copyright 2016 Gordon Ross <[email protected]>
14+
#
15+
16+
MODULE = foo.so
17+
MDBTGT = kvm
18+
19+
MODSRCS = foo.c
20+
21+
include ../../../Makefile.cmd
22+
include ../../Makefile.ia32
23+
include ../../Makefile.module
24+
25+
CPPFLAGS += -I$(SRC)/uts/common

usr/src/pkg/manifests/app-example-foo.mf

+4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ dir path=usr/share/man/man7
3636
file path=kernel/drv/$(ARCH64)/foo
3737
$(i386_ONLY)file path=kernel/drv/foo
3838
file path=kernel/drv/foo.conf
39+
file path=kernel/kmdb/$(ARCH64)/foo
40+
$(i386_ONLY)file path=kernel/kmdb/foo
3941
file path=usr/bin/foo mode=0555
4042
file path=usr/include/libfoo/foo.h
4143
file path=usr/lib/$(ARCH64)/libfoo.so.1
4244
file path=usr/lib/$(ARCH64)/llib-lfoo.ln
4345
file path=usr/lib/libfoo.so.1
4446
file path=usr/lib/llib-lfoo
4547
file path=usr/lib/llib-lfoo.ln
48+
file path=usr/lib/mdb/kvm/amd64/fo.so
49+
file path=usr/lib/mdb/kvm/foo.so
4650
file path=usr/share/man/man1/foo.1
4751
file path=usr/share/man/man3x/foo.3x
4852
file path=usr/share/man/man7/foo.7

0 commit comments

Comments
 (0)