xref: /haiku/src/kits/debugger/dwarf/AttributeValue.cpp (revision 3634f142352af2428aed187781fc9d75075e9140)
1 /*
2  * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "AttributeValue.h"
7 
8 #include <stdio.h>
9 
10 #include "AttributeClasses.h"
11 
12 
13 const char*
14 AttributeValue::ToString(char* buffer, size_t size)
15 {
16 	switch (attributeClass) {
17 		case ATTRIBUTE_CLASS_ADDRESS:
18 			snprintf(buffer, size, "%#" B_PRIx64, address);
19 			return buffer;
20 		case ATTRIBUTE_CLASS_BLOCK:
21 			snprintf(buffer, size, "(%p, %#" B_PRIx64 ")", block.data,
22 				block.length);
23 			return buffer;
24 		case ATTRIBUTE_CLASS_CONSTANT:
25 			snprintf(buffer, size, "%#" B_PRIx64, constant);
26 			return buffer;
27 		case ATTRIBUTE_CLASS_FLAG:
28 			snprintf(buffer, size, "%s", flag ? "true" : "false");
29 			return buffer;
30 		case ATTRIBUTE_CLASS_ADDRPTR:
31 		case ATTRIBUTE_CLASS_LINEPTR:
32 		case ATTRIBUTE_CLASS_LOCLIST:
33 		case ATTRIBUTE_CLASS_LOCLISTPTR:
34 		case ATTRIBUTE_CLASS_MACPTR:
35 		case ATTRIBUTE_CLASS_RANGELIST:
36 		case ATTRIBUTE_CLASS_RANGELISTPTR:
37 		case ATTRIBUTE_CLASS_STROFFSETSPTR:
38 			snprintf(buffer, size, "%#" B_PRIx64, pointer);
39 			return buffer;
40 		case ATTRIBUTE_CLASS_REFERENCE:
41 			snprintf(buffer, size, "%p", reference);
42 			return buffer;
43 		case ATTRIBUTE_CLASS_STRING:
44 			snprintf(buffer, size, "\"%s\"", string);
45 			return buffer;
46 
47 		default:
48 		case ATTRIBUTE_CLASS_UNKNOWN:
49 			return "<unknown>";
50 	}
51 
52 	return buffer;
53 }
54