Created
June 3, 2020 23:20
-
-
Save aditya7fb/8d9ed4d86678b409e3b28d885c95e29a to your computer and use it in GitHub Desktop.
running function entry instrumentation on quicksort example from G4G
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
./bin/clang++ test.cpp test1.cpp -arch arm64 -mllvm -enable-func-entry-instrumentation -O2 -mllvm -func-entry-instrumentation-writemethod=1 | |
Contents of section __la_symbol_ptr: | |
10000c000 247f0000 01000000 307f0000 01000000 $.......0....... | |
10000c010 3c7f0000 01000000 <....... | |
Contents of section __llvm_funcentry: | |
10000c020 dcdfe5c6 5cf4ac04 1d030000 00acacac ....\........... | |
10000c030 dcdb78b3 cc9999ee dd040000 00acacac ..x............. | |
10000c040 ac . | |
Contents of section __llvm_femapping: | |
10000c050 dcdfe5c6 5cf4ac04 1d030000 00f195a9 ....\........... | |
10000c060 8a2f70a5 840d0000 00d1bbbe e85e7b89 ./p..........^{. | |
10000c070 3e0e0000 00c3ec88 8923205e 380f0000 >........# ^8... | |
10000c080 00000000 00000000 00000000 00000000 ................ | |
10000c090 dcdb78b3 cc9999ee dd040000 00420bc1 ..x..........B.. | |
10000c0a0 4550ce40 300d0000 000ee7f6 4ec18b82 EP.@0.......N... | |
10000c0b0 0e0e0000 000bd51d f65fbf92 300f0000 ........._..0... | |
10000c0c0 00e8c546 0e951330 ae100000 00 ...F...0..... | |
*/ | |
//char a[3] ={1,2,3}; | |
//char b[] = {4,5,6,7,8,9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}; | |
/* C implementation QuickSort */ | |
#include<stdio.h> | |
// A utility function to swap two elements | |
void swap(int* a, int* b) | |
{ | |
int t = *a; | |
*a = *b; | |
*b = t; | |
} | |
/* This function takes last element as pivot, places | |
the pivot element at its correct position in sorted | |
array, and places all smaller (smaller than pivot) | |
to left of pivot and all greater elements to right | |
of pivot */ | |
int partition (int arr[], int low, int high) | |
{ | |
int pivot = arr[high]; // pivot | |
int i = (low - 1); // Index of smaller element | |
for (int j = low; j <= high- 1; j++) | |
{ | |
// If current element is smaller than the pivot | |
if (arr[j] < pivot) | |
{ | |
i++; // increment index of smaller element | |
swap(&arr[i], &arr[j]); | |
} | |
} | |
swap(&arr[i + 1], &arr[high]); | |
return (i + 1); | |
} | |
/* The main function that implements QuickSort | |
arr[] --> Array to be sorted, | |
low --> Starting index, | |
high --> Ending index */ | |
void quickSort(int arr[], int low, int high) | |
{ | |
if (low < high) | |
{ | |
/* pi is partitioning index, arr[p] is now | |
at right place */ | |
int pi = partition(arr, low, high); | |
// Separately sort elements before | |
// partition and after partition | |
quickSort(arr, low, pi - 1); | |
quickSort(arr, pi + 1, high); | |
} | |
} | |
/* Function to print an array */ | |
void printArray(int arr[], int size) | |
{ | |
int i; | |
for (i=0; i < size; i++) | |
printf("%d ", arr[i]); | |
printf("n"); | |
} | |
// Driver program to test above functions | |
int main() | |
{ | |
int arr[] = {10, 7, 8, 9, 1, 5}; | |
int n = sizeof(arr)/sizeof(arr[0]); | |
quickSort(arr, 0, n-1); | |
//printf("Sorted array: n"); | |
//printArray(arr, n); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// A utility function to swap two elements | |
void swap1(int* a, int* b) | |
{ | |
int t = *a; | |
*a = *b; | |
*b = t; | |
} | |
/* This function takes last element as pivot, places | |
the pivot element at its correct position in sorted | |
array, and places all smaller (smaller than pivot) | |
to left of pivot and all greater elements to right | |
of pivot */ | |
int partition1 (int arr[], int low, int high) | |
{ | |
int pivot = arr[high]; // pivot | |
int i = (low - 1); // Index of smaller element | |
for (int j = low; j <= high- 1; j++) | |
{ | |
// If current element is smaller than the pivot | |
if (arr[j] < pivot) | |
{ | |
i++; // increment index of smaller element | |
swap1(&arr[i], &arr[j]); | |
} | |
} | |
swap1(&arr[i + 1], &arr[high]); | |
return (i + 1); | |
} | |
/* The main function that implements QuickSort | |
arr[] --> Array to be sorted, | |
low --> Starting index, | |
high --> Ending index */ | |
void quickSort1(int arr[], int low, int high) | |
{ | |
if (low < high) | |
{ | |
/* pi is partitioning index, arr[p] is now | |
at right place */ | |
int pi = partition1(arr, low, high); | |
// Separately sort elements before | |
// partition and after partition | |
quickSort1(arr, low, pi - 1); | |
quickSort1(arr, pi + 1, high); | |
} | |
} | |
/* Function to print an array */ | |
void printArray1(int arr[], int size) | |
{ | |
int i; | |
for (i=0; i < size; i++) | |
printf("%d ", arr[i]); | |
printf("n"); | |
} | |
// Driver program to test above functions | |
int main1() | |
{ | |
int arr[] = {10, 7, 8, 9, 1, 5}; | |
int n = sizeof(arr)/sizeof(arr[0]); | |
quickSort1(arr, 0, n-1); | |
printf("Sorted array: n"); | |
printArray1(arr, n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using xray:
The output of relevant sections:
Using function entry instrumentation:
The output of relevant sections: