xref: /haiku/src/kits/debugger/dwarf/AttributeValue.cpp (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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_LINEPTR:
31 		case ATTRIBUTE_CLASS_LOCLISTPTR:
32 		case ATTRIBUTE_CLASS_MACPTR:
33 		case ATTRIBUTE_CLASS_RANGELISTPTR:
34 			snprintf(buffer, size, "%#" B_PRIx64, pointer);
35 			return buffer;
36 		case ATTRIBUTE_CLASS_REFERENCE:
37 			snprintf(buffer, size, "%p", reference);
38 			return buffer;
39 		case ATTRIBUTE_CLASS_STRING:
40 			snprintf(buffer, size, "\"%s\"", string);
41 			return buffer;
42 
43 		default:
44 		case ATTRIBUTE_CLASS_UNKNOWN:
45 			return "<unknown>";
46 	}
47 
48 	return buffer;
49 }
50