Skip to content

Commit 058ecb5

Browse files
committed
GP-0 Revert GP-4886 change pending further review and rework
1 parent 81432f7 commit 058ecb5

File tree

6 files changed

+28
-82
lines changed

6 files changed

+28
-82
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledDataType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public class DemangledDataType extends DemangledType {
9595
private static final String UNSIGNED_LONG = "unsigned long";
9696

9797
public final static String[] PRIMITIVES =
98-
{ VOID, BOOL, CHAR, WCHAR_T, WCHAR16, WCHAR32, CHAR8_T, SHORT, INT, INT0_T, LONG, LONG_LONG,
99-
FLOAT, FLOAT2, DOUBLE, INT128, FLOAT128, LONG_DOUBLE, };
98+
{ VOID, BOOL, CHAR, WCHAR_T, WCHAR16, WCHAR32, CHAR8_T, SHORT, INT, INT0_T, LONG,
99+
LONG_LONG, FLOAT, FLOAT2, DOUBLE, INT128, FLOAT128, LONG_DOUBLE, };
100100

101101
private int arrayDimensions = 0;
102102
private boolean isClass;
@@ -200,10 +200,10 @@ else if (isClass() || name.equals(STRING)) {
200200
else if (dt == null) {
201201

202202
// I don't know what this is
203-
// If it isn't pointed to, or isn't a referent, then assume undefined typedef.
203+
// If it isn't pointed to, or isn't a referent, then assume typedef.
204204
if (!(isReference() || isPointer())) { // Unknown type
205205
dt = new TypedefDataType(getDemanglerCategoryPath(getNamespace()), name,
206-
DataType.DEFAULT);
206+
new DWordDataType());
207207
}
208208
else {
209209
// try creating empty structures for unknown types instead.

Ghidra/Features/GnuDemangler/src/test/java/ghidra/app/util/demangler/gnu/GnuDemanglerTest.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import ghidra.app.util.demangler.*;
2727
import ghidra.program.database.ProgramDB;
2828
import ghidra.program.model.address.Address;
29-
import ghidra.program.model.data.DataType;
3029
import ghidra.program.model.data.TerminatedStringDataType;
3130
import ghidra.program.model.listing.CodeUnit;
3231
import ghidra.program.model.listing.Data;
@@ -129,60 +128,6 @@ public void testUseStandardReplacements() throws Exception {
129128
fullSignature);
130129
}
131130

132-
@Test
133-
public void testUseStandardReplacements2() throws Exception {
134-
135-
//
136-
// Mangled: _ZN7Greeter5greetENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
137-
//
138-
// Demangled: undefined Greeter::greet(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>)
139-
//
140-
// Replaced: undefined Greeter::greet(std::string)
141-
//
142-
String mangled = "_ZN7Greeter5greetENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE";
143-
144-
GnuDemangler demangler = new GnuDemangler();
145-
demangler.canDemangle(program);// this perform initialization
146-
147-
GnuDemanglerOptions options = new GnuDemanglerOptions();
148-
options.setUseStandardReplacements(true);
149-
DemangledFunction dobj = (DemangledFunction) demangler.demangle(mangled, options);
150-
assertNotNull(dobj);
151-
152-
String signature = dobj.getSignature();
153-
assertEquals("undefined Greeter::greet(std::string)", signature);
154-
155-
DemangledParameter demangledParameter = dobj.getParameters().get(0);
156-
DemangledDataType type = demangledParameter.getType();
157-
DataType dt = type.getDataType(program.getDataTypeManager());
158-
assertTrue(dt.isNotYetDefined());
159-
//@formatter:off
160-
assertEquals("/Demangler/std/string\n" +
161-
"pack(disabled)\n" +
162-
"Structure string {\n" +
163-
"}\n" +
164-
"Length: 0 Alignment: 1\n", dt.toString());
165-
//@formatter:on
166-
167-
//
168-
// Now disable demangled string replacement
169-
//
170-
options.setUseStandardReplacements(false);
171-
dobj = (DemangledFunction) demangler.demangle(mangled, options);
172-
assertNotNull(dobj);
173-
174-
String fullSignature = dobj.getSignature();
175-
assertEquals(
176-
"undefined Greeter::greet(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>)",
177-
fullSignature);
178-
179-
demangledParameter = dobj.getParameters().get(0);
180-
type = demangledParameter.getType();
181-
dt = type.getDataType(program.getDataTypeManager());
182-
assertEquals("typedef basic_string undefined", dt.toString());
183-
184-
}
185-
186131
@Test
187132
public void testDemangleOnlyKnownPatterns_True() throws Exception {
188133

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionDB.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -2470,6 +2470,16 @@ public SourceType getSignatureSource() {
24702470
return thunkedFunction.getSignatureSource();
24712471
}
24722472

2473+
// Force DEFAULT source if any param has unassigned storage
2474+
if (!getReturn().isValid()) {
2475+
return SourceType.DEFAULT;
2476+
}
2477+
for (Parameter param : getParameters()) {
2478+
if (!param.isValid()) {
2479+
return SourceType.DEFAULT;
2480+
}
2481+
}
2482+
24732483
return getStoredSignatureSource();
24742484
}
24752485
finally {

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/ParamListStandard.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,7 +23,8 @@
2323

2424
import ghidra.program.model.address.Address;
2525
import ghidra.program.model.address.AddressSpace;
26-
import ghidra.program.model.data.*;
26+
import ghidra.program.model.data.DataType;
27+
import ghidra.program.model.data.DataTypeManager;
2728
import ghidra.program.model.lang.protorules.*;
2829
import ghidra.program.model.listing.Program;
2930
import ghidra.program.model.listing.VariableStorage;
@@ -132,12 +133,6 @@ public int assignAddress(DataType dt, PrototypePieces proto, int pos, DataTypeMa
132133
if (dt.isZeroLength()) {
133134
return AssignAction.NO_ASSIGNMENT;
134135
}
135-
if (dt == DataType.DEFAULT) {
136-
return AssignAction.NO_ASSIGNMENT;
137-
}
138-
if (dt instanceof TypeDef td && td.getBaseDataType() == DataType.DEFAULT) {
139-
return AssignAction.NO_ASSIGNMENT;
140-
}
141136
for (ModelRule modelRule : modelRules) {
142137
int responseCode = modelRule.assignAddress(dt, proto, pos, dtManager, status, res);
143138
if (responseCode != AssignAction.FAIL) {

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -210,12 +210,11 @@ public void grabFromFunction(boolean includeDefaultNames) {
210210
pcaddr = pcaddr.subtractWrap(1);
211211

212212
List<HighSymbol> paramList = new ArrayList<>();
213-
boolean internalInvalid = false;
214213
for (int i = 0; i < p.length; ++i) {
215214
Parameter var = p[i];
216215
if (!var.isValid()) {
217-
internalInvalid = true;
218-
break;
216+
// TODO: exclude parameters which don't have valid storage ??
217+
continue;
219218
}
220219
DataType dt = var.getDataType();
221220
String name = var.getName();
@@ -244,12 +243,6 @@ public void grabFromFunction(boolean includeDefaultNames) {
244243
paramSymbol.setNameLock(namelock);
245244
paramSymbol.setTypeLock(lock);
246245
}
247-
if (internalInvalid) {
248-
// Can only send down a partial prototype. Let decompiler try to recover the whole.
249-
for (HighSymbol paramSymbol : paramList) {
250-
paramSymbol.setTypeLock(false);
251-
}
252-
}
253246

254247
paramSymbols = new HighSymbol[paramList.size()];
255248
paramList.toArray(paramSymbols);

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,10 @@ else if (type instanceof AbstractFloatDataType) {
11531153
private void generateCoreTypes() {
11541154
voidDt = new VoidDataType(progDataTypes);
11551155
coreBuiltin = new HashMap<Long, TypeMap>();
1156-
TypeMap type = new TypeMap(displayLanguage, VoidDataType.dataType, "void", false, false,
1156+
TypeMap type = new TypeMap(DataType.DEFAULT, "undefined", "unknown", false, false,
1157+
DEFAULT_DECOMPILER_ID);
1158+
coreBuiltin.put(type.id, type);
1159+
type = new TypeMap(displayLanguage, VoidDataType.dataType, "void", false, false,
11571160
builtInDataTypes);
11581161
coreBuiltin.put(type.id, type);
11591162

0 commit comments

Comments
 (0)