Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0cf14f4b477e51813e0eb9be041f10687323f685 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************
 * Copyright (c) 2000, 2006 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.debug.mi.core.output;

import java.util.ArrayList;
import java.util.List;

/**
 * GDB/MI disassemble parsing response.
 */
public class MIDataDisassembleInfo extends MIInfo {

	MISrcAsm[] src_asm;
	MIAsm[] asm;
	boolean mixed;

	public MIDataDisassembleInfo(MIOutput rr) {
		super(rr);
		mixed = false;
		parse();
	}

	public MIAsm[] getMIAsms() {
		return asm;
	}

	public boolean isMixed() {
		return mixed;
	}

	public MISrcAsm[] getMISrcAsms() {
		return src_asm;
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("asm_insns=["); //$NON-NLS-1$
		
		if (isMixed()) {
			MISrcAsm[] array = getMISrcAsms();
			for (int i = 0; i < array.length; i++) {
				if (i != 0) {
					buffer.append(',');
				}
				buffer.append(array[i].toString());
			}
		} else {
			MIAsm[] array = getMIAsms();
			for (int i = 0; i < array.length; i++) {
				if (i != 0) {
					buffer.append(',');
				}
				buffer.append(array[i].toString());
			}
		}
		buffer.append("]"); //$NON-NLS-1$
		return buffer.toString();
	}

	void parse() {
		List asmList = new ArrayList();
		List srcList = new ArrayList();
		if (isDone()) {
			MIOutput out = getMIOutput();
			MIResultRecord rr = out.getMIResultRecord();
			if (rr != null) {
				MIResult[] results =  rr.getMIResults();
				for (int i = 0; i < results.length; i++) {
					String var = results[i].getVariable();
					if (var.equals("asm_insns")) { //$NON-NLS-1$
						MIValue value = results[i].getMIValue();
						if (value instanceof MIList) {
							parse((MIList)value, srcList, asmList);
						}
					}
				}
			}
		}
		src_asm = (MISrcAsm[])srcList.toArray(new MISrcAsm[srcList.size()]);
		asm = (MIAsm[])asmList.toArray(new MIAsm[asmList.size()]);
	}

	void parse(MIList list, List srcList, List asmList) {
		// src and assembly is different
		
		// Mixed mode.
		MIResult[] results = list.getMIResults();
		if (results != null && results.length > 0) {
			for (int i = 0; i < results.length; i++) {
				String var = results[i].getVariable();
				if (var.equals("src_and_asm_line")) { //$NON-NLS-1$
					MIValue value = results[i].getMIValue();
					if (value instanceof MITuple) {
						MISrcAsm miSrcAsm = new MISrcAsm((MITuple) value);
						if (miSrcAsm.getMIAsms() != null && miSrcAsm.getMIAsms().length > 0) {
							srcList.add(miSrcAsm);
						}
					}
				}
			}
			mixed = true;
		}

		// Non Mixed with source
		MIValue[] values = list.getMIValues();
		if (values != null && values.length > 0) {
			for (int i = 0; i < values.length; i++) {
				if (values[i] instanceof MITuple) {
					asmList.add(new MIAsm((MITuple)values[i]));
				}
			}
			mixed = false;
		}
	}
}

Back to the top