xref: /illumos-gate/usr/src/lib/libdwarf/common/pro_finish.c (revision 6f1fa39e3cf1b335f342bbca41590e9d76ab29b7)
1 /*
2   Copyright (C) 2000,2004 Silicon Graphics, Inc.  All Rights Reserved.
3   Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved.
4   Portions Copyright 2011-2018 David Anderson. All rights reserved.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of version 2.1 of the GNU Lesser General Public License
8   as published by the Free Software Foundation.
9 
10   This program is distributed in the hope that it would be useful, but
11   WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 
14   Further, this software is distributed without any warranty that it is
15   free of the rightful claim of any third person regarding infringement
16   or the like.  Any license provided herein, whether implied or
17   otherwise, applies only to this software file.  Patent licenses, if
18   any, provided herein do not apply to combinations of this program with
19   other software, or any other product whatsoever.
20 
21   You should have received a copy of the GNU Lesser General Public
22   License along with this program; if not, write the Free Software
23   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
24   USA.
25 
26 */
27 
28 #include "config.h"
29 #include "libdwarfdefs.h"
30 #include "pro_incl.h"
31 #include <stddef.h>
32 #include "dwarf.h"
33 #include "libdwarf.h"
34 #include "pro_opaque.h"
35 #include "pro_error.h"
36 #include "pro_alloc.h"
37 
38 
39 /*  This routine deallocates all memory, and does some
40     finishing up
41     This is the original version using a badly designed return
42     value approach.
43     Please use dwarf_producer_finish_a() instead.  */
44 /*ARGSUSED*/ Dwarf_Unsigned
45 dwarf_producer_finish(Dwarf_P_Debug dbg, Dwarf_Error * error)
46 {
47     int res = dwarf_producer_finish_a(dbg,error);
48     if (res != DW_DLV_OK) {
49         return DW_DLV_NOCOUNT;
50     }
51     return 0;
52 }
53 /*  This routine deallocates all memory, and does some
54     finishing up.  New September 2016. */
55 int
56 dwarf_producer_finish_a(Dwarf_P_Debug dbg, Dwarf_Error * error)
57 {
58     if (dbg->de_version_magic_number != PRO_VERSION_MAGIC) {
59         DWARF_P_DBG_ERROR(dbg, DW_DLE_IA, DW_DLV_ERROR);
60     }
61 
62     /* this frees all blocks, then frees dbg. */
63     _dwarf_p_dealloc_all(dbg);
64     return DW_DLV_OK ;
65 }
66 
67 /* FIXME: Add stats for debug_line_str. */
68 int
69 dwarf_pro_get_string_stats(Dwarf_P_Debug dbg,
70     Dwarf_Unsigned * str_count,
71     Dwarf_Unsigned * str_total_length,
72     Dwarf_Unsigned * strp_count_debug_str,
73     Dwarf_Unsigned * strp_len_debug_str,
74     Dwarf_Unsigned * strp_reused_count,
75     Dwarf_Unsigned * strp_reused_len,
76     Dwarf_Error    * error)
77 {
78     struct Dwarf_P_Str_stats_s* ps = 0;
79     if (!dbg) {
80         _dwarf_p_error(dbg, error, DW_DLE_IA);
81         return DW_DLV_ERROR;
82     }
83     if (dbg->de_version_magic_number !=PRO_VERSION_MAGIC ) {
84         _dwarf_p_error(dbg, error, DW_DLE_VMM);
85         return DW_DLV_ERROR;
86     }
87     *str_count        = dbg->de_stats.ps_str_count;
88     *str_total_length = dbg->de_stats.ps_str_total_length;
89     ps = &dbg->de_stats.ps_strp;
90     *strp_count_debug_str = ps->ps_strp_count_debug_str;
91     *strp_len_debug_str   = ps->ps_strp_len_debug_str;
92     *strp_reused_count    = ps->ps_strp_reused_count;
93     *strp_reused_len      = ps->ps_strp_reused_len;
94     return DW_DLV_OK;
95 }
96