[Lldb-commits] [lldb] r125314 - in /lldb/trunk: source/Expression/IRForTarget.cpp test/foundation/const-strings.m
Sean Callanan
scallanan at apple.com
Thu Feb 10 14:17:54 PST 2011
Author: spyffe
Date: Thu Feb 10 16:17:53 2011
New Revision: 125314
URL: http://llvm.org/viewvc/llvm-project?rev=125314&view=rev
Log:
Fixes for two bugs:
- Objective-C constant strings were being
NULL-terminated erroneously.
- Empty Objective-C constant strings were not
being generated correctly.
Also added the template for a test of these
fixes.
Added:
lldb/trunk/test/foundation/const-strings.m
Modified:
lldb/trunk/source/Expression/IRForTarget.cpp
Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=125314&r1=125313&r2=125314&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Thu Feb 10 16:17:53 2011
@@ -478,13 +478,18 @@
m_CFStringCreateWithBytes = ConstantExpr::getIntToPtr(CFSCWB_addr_int, CFSCWB_ptr_ty);
}
- ConstantArray *string_array = dyn_cast<ConstantArray>(cstr->getInitializer());
+ ConstantArray *string_array;
+
+ if (cstr)
+ string_array = dyn_cast<ConstantArray>(cstr->getInitializer());
+ else
+ string_array = NULL;
SmallVector <Value*, 5> CFSCWB_arguments;
Constant *alloc_arg = Constant::getNullValue(i8_ptr_ty);
- Constant *bytes_arg = ConstantExpr::getBitCast(cstr, i8_ptr_ty);
- Constant *numBytes_arg = ConstantInt::get(intptr_ty, string_array->getType()->getNumElements(), false);
+ Constant *bytes_arg = cstr ? ConstantExpr::getBitCast(cstr, i8_ptr_ty) : Constant::getNullValue(i8_ptr_ty);
+ Constant *numBytes_arg = ConstantInt::get(intptr_ty, cstr ? string_array->getType()->getNumElements() - 1 : 0, false);
Constant *encoding_arg = ConstantInt::get(i32_ty, 0x0600, false); /* 0x0600 is kCFStringEncodingASCII */
Constant *isExternal_arg = ConstantInt::get(i8_ty, 0x0, false); /* 0x0 is false */
@@ -664,9 +669,8 @@
return false;
}
-
- ConstantArray *cstr_array = dyn_cast<ConstantArray>(cstr_global->getInitializer());
-
+
+ /*
if (!cstr_array)
{
if (log)
@@ -688,9 +692,20 @@
return false;
}
+ */
+
+ ConstantArray *cstr_array = dyn_cast<ConstantArray>(cstr_global->getInitializer());
if (log)
- log->Printf("Found NSString constant %s, which contains \"%s\"", vi->first(), cstr_array->getAsString().c_str());
+ {
+ if (cstr_array)
+ log->Printf("Found NSString constant %s, which contains \"%s\"", vi->first(), cstr_array->getAsString().c_str());
+ else
+ log->Printf("Found NSString constant %s, which contains \"\"", vi->first());
+ }
+
+ if (!cstr_array)
+ cstr_global = NULL;
if (!RewriteObjCConstString(llvm_module, nsstring_global, cstr_global, FirstEntryInstruction))
{
Added: lldb/trunk/test/foundation/const-strings.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/foundation/const-strings.m?rev=125314&view=auto
==============================================================================
--- lldb/trunk/test/foundation/const-strings.m (added)
+++ lldb/trunk/test/foundation/const-strings.m Thu Feb 10 16:17:53 2011
@@ -0,0 +1,23 @@
+#import <Foundation/Foundation.h>
+
+// Tests to run:
+
+// Breakpoint 1
+// --
+// (lldb) expr (int)[str compare:@"hello"]
+// (int) $0 = 0
+// (lldb) expr (int)[str compare:@"world"]
+// (int) $1 = -1
+// (lldb) expr (int)[@"" length]
+// (int) $2 = 0
+
+int main ()
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *str = [NSString stringWithCString:"hello" encoding:NSASCIIStringEncoding];
+
+ NSLog(@"String \"%@\" has length %d", str, [str length]); // Breakpoint 1
+
+ [pool drain];
+}
More information about the lldb-commits
mailing list