xref: /netbsd/usr.sbin/kvm_mkdb/nlist.c (revision d6aaec91)
1*d6aaec91Ssevan /* $NetBSD: nlist.c,v 1.20 2018/01/23 21:06:25 sevan Exp $ */
2326b2259Sagc 
3326b2259Sagc /*-
4326b2259Sagc  * Copyright (c) 1990, 1993
5326b2259Sagc  *	The Regents of the University of California.  All rights reserved.
6326b2259Sagc  *
7326b2259Sagc  * Redistribution and use in source and binary forms, with or without
8326b2259Sagc  * modification, are permitted provided that the following conditions
9326b2259Sagc  * are met:
10326b2259Sagc  * 1. Redistributions of source code must retain the above copyright
11326b2259Sagc  *    notice, this list of conditions and the following disclaimer.
12326b2259Sagc  * 2. Redistributions in binary form must reproduce the above copyright
13326b2259Sagc  *    notice, this list of conditions and the following disclaimer in the
14326b2259Sagc  *    documentation and/or other materials provided with the distribution.
15326b2259Sagc  * 3. Neither the name of the University nor the names of its contributors
16326b2259Sagc  *    may be used to endorse or promote products derived from this software
17326b2259Sagc  *    without specific prior written permission.
18326b2259Sagc  *
19326b2259Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20326b2259Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21326b2259Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22326b2259Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23326b2259Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24326b2259Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25326b2259Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26326b2259Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27326b2259Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28326b2259Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29326b2259Sagc  * SUCH DAMAGE.
30326b2259Sagc  */
3163488d73Sthorpej 
3261f28255Scgd /*-
33c347bc09Scgd  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
3461f28255Scgd  *
3561f28255Scgd  * Redistribution and use in source and binary forms, with or without
3661f28255Scgd  * modification, are permitted provided that the following conditions
3761f28255Scgd  * are met:
3861f28255Scgd  * 1. Redistributions of source code must retain the above copyright
3961f28255Scgd  *    notice, this list of conditions and the following disclaimer.
4061f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
4161f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
4261f28255Scgd  *    documentation and/or other materials provided with the distribution.
4361f28255Scgd  * 3. All advertising materials mentioning features or use of this software
4461f28255Scgd  *    must display the following acknowledgement:
4561f28255Scgd  *	This product includes software developed by the University of
4661f28255Scgd  *	California, Berkeley and its contributors.
4761f28255Scgd  * 4. Neither the name of the University nor the names of its contributors
4861f28255Scgd  *    may be used to endorse or promote products derived from this software
4961f28255Scgd  *    without specific prior written permission.
5061f28255Scgd  *
5161f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5261f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5361f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5461f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5561f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5661f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5761f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5861f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5961f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6061f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6161f28255Scgd  * SUCH DAMAGE.
6261f28255Scgd  */
6361f28255Scgd 
64e5436d32Slukem #include <sys/cdefs.h>
6561f28255Scgd #ifndef lint
6663488d73Sthorpej #if 0
6763488d73Sthorpej static char sccsid[] = "from: @(#)nlist.c	8.1 (Berkeley) 6/6/93";
6863488d73Sthorpej #else
69*d6aaec91Ssevan __RCSID("$NetBSD: nlist.c,v 1.20 2018/01/23 21:06:25 sevan Exp $");
7063488d73Sthorpej #endif
7161f28255Scgd #endif /* not lint */
7261f28255Scgd 
7361f28255Scgd #include <sys/param.h>
74ec1b7778Spk 
7561f28255Scgd #include <a.out.h>
7661f28255Scgd #include <db.h>
77ec1b7778Spk #include <err.h>
7861f28255Scgd #include <errno.h>
79ec1b7778Spk #include <fcntl.h>
8061f28255Scgd #include <kvm.h>
81ec1b7778Spk #include <limits.h>
8261f28255Scgd #include <stdio.h>
8361f28255Scgd #include <stdlib.h>
84ec1b7778Spk #include <string.h>
85ec1b7778Spk #include <unistd.h>
86ec1b7778Spk 
87ec1b7778Spk #include "extern.h"
8861f28255Scgd 
89c347bc09Scgd static struct {
90*d6aaec91Ssevan         int     (*knlist)(const char *, DB *);
91c347bc09Scgd } knlist_fmts[] = {
92c347bc09Scgd #ifdef NLIST_AOUT
93c347bc09Scgd         {       create_knlist_aout          },
94c347bc09Scgd #endif
95ec7f04c3Sitojun #ifdef NLIST_COFF
96ec7f04c3Sitojun         {       create_knlist_coff         },
97ec7f04c3Sitojun #endif
98c347bc09Scgd #ifdef NLIST_ECOFF
99c347bc09Scgd         {       create_knlist_ecoff         },
100c347bc09Scgd #endif
101c347bc09Scgd #ifdef NLIST_ELF32
102c347bc09Scgd         {       create_knlist_elf32         },
103c347bc09Scgd #endif
104c347bc09Scgd #ifdef NLIST_ELF64
105c347bc09Scgd         {       create_knlist_elf64         },
106c347bc09Scgd #endif
107c347bc09Scgd };
1086ff21e94Spk 
1096ff21e94Spk void
create_knlist(const char * name,DB * db)110*d6aaec91Ssevan create_knlist(const char *name, DB *db)
11161f28255Scgd {
112c347bc09Scgd 	int i;
11361f28255Scgd 
114c347bc09Scgd         for (i = 0; i < sizeof(knlist_fmts) / sizeof(knlist_fmts[0]); i++)
115c347bc09Scgd                 if ((*knlist_fmts[i].knlist)(name, db) != -1)
116c347bc09Scgd                         return;
117c347bc09Scgd 	warnx("%s: file format not recognized", name);
118c347bc09Scgd 	punt();
11961f28255Scgd }
120