123b5c241Stomee /* 223b5c241Stomee * CDDL HEADER START 323b5c241Stomee * 423b5c241Stomee * The contents of this file are subject to the terms of the 523b5c241Stomee * Common Development and Distribution License (the "License"). 623b5c241Stomee * You may not use this file except in compliance with the License. 723b5c241Stomee * 823b5c241Stomee * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 923b5c241Stomee * or http://www.opensolaris.org/os/licensing. 1023b5c241Stomee * See the License for the specific language governing permissions 1123b5c241Stomee * and limitations under the License. 1223b5c241Stomee * 1323b5c241Stomee * When distributing Covered Code, include this CDDL HEADER in each 1423b5c241Stomee * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1523b5c241Stomee * If applicable, add the following below this CDDL HEADER, with the 1623b5c241Stomee * fields enclosed by brackets "[]" replaced with your own identifying 1723b5c241Stomee * information: Portions Copyright [yyyy] [name of copyright owner] 1823b5c241Stomee * 1923b5c241Stomee * CDDL HEADER END 2023b5c241Stomee */ 2123b5c241Stomee 2223b5c241Stomee /* 238cb74972SJonathan Haslam * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2423b5c241Stomee * Use is subject to license terms. 2523b5c241Stomee */ 2623b5c241Stomee 2723b5c241Stomee import org.opensolaris.os.dtrace.*; 2823b5c241Stomee 2923b5c241Stomee /** 3023b5c241Stomee * Regression for bug 6413280 lookupKernelFunction() and 3123b5c241Stomee * lookupUserFunction() truncate last character. 3223b5c241Stomee */ 3323b5c241Stomee public class TestFunctionLookup { 3423b5c241Stomee static final String kernelLookupProgram = "sdt:::callout-start { " + 3523b5c241Stomee "@[((callout_t *)arg0)->c_func] = count(); }"; 3623b5c241Stomee static final String userLookupProgram = "pid$target::f2:entry { " + 3723b5c241Stomee "@[arg0] = count(); }"; 3823b5c241Stomee 3923b5c241Stomee public static void main(String[] args)4023b5c241Stomee main(String[] args) 4123b5c241Stomee { 4223b5c241Stomee if (args.length != 1) { 4323b5c241Stomee System.err.println("usage: java TestFunctionLookup <command>"); 4423b5c241Stomee System.exit(1); 4523b5c241Stomee } 4623b5c241Stomee String cmd = args[0]; 4723b5c241Stomee 4823b5c241Stomee Consumer consumer = new LocalConsumer(); 4923b5c241Stomee try { 5023b5c241Stomee consumer.open(); 5123b5c241Stomee consumer.compile(kernelLookupProgram); 5223b5c241Stomee consumer.enable(); 5323b5c241Stomee consumer.go(); 5423b5c241Stomee Aggregate a; 5523b5c241Stomee Number address; 5623b5c241Stomee String f; 5723b5c241Stomee boolean done = false; 5823b5c241Stomee for (int i = 0; (i < 20) && !done; ++i) { 59*4d0eb50eSRichard PALO Thread.sleep(100); 6023b5c241Stomee a = consumer.getAggregate(); 6123b5c241Stomee for (Aggregation agg : a.getAggregations()) { 6223b5c241Stomee for (Tuple tuple : agg.asMap().keySet()) { 6323b5c241Stomee address = (Number)tuple.get(0).getValue(); 6423b5c241Stomee if (address instanceof Integer) { 6523b5c241Stomee int addr = (Integer)address; 6623b5c241Stomee f = consumer.lookupKernelFunction(addr); 6723b5c241Stomee } else { 6823b5c241Stomee long addr = (Long)address; 6923b5c241Stomee f = consumer.lookupKernelFunction(addr); 7023b5c241Stomee } 718cb74972SJonathan Haslam if (f.equals("genunix`cv_wakeup")) { 7223b5c241Stomee System.out.println(f); 7323b5c241Stomee done = true; 7423b5c241Stomee } 7523b5c241Stomee } 7623b5c241Stomee } 7723b5c241Stomee } 7823b5c241Stomee consumer.close(); 7923b5c241Stomee } catch (Exception e) { 8023b5c241Stomee e.printStackTrace(); 8123b5c241Stomee System.exit(1); 8223b5c241Stomee } 8323b5c241Stomee 8423b5c241Stomee consumer = new LocalConsumer(); 8523b5c241Stomee try { 8623b5c241Stomee consumer.open(); 8723b5c241Stomee int pid = consumer.createProcess(cmd); 8823b5c241Stomee consumer.compile(userLookupProgram); 8923b5c241Stomee consumer.enable(); 9023b5c241Stomee consumer.go(); 91*4d0eb50eSRichard PALO Thread.sleep(500); 9223b5c241Stomee Aggregate a = consumer.getAggregate(); 9323b5c241Stomee Number address; 9423b5c241Stomee String f; 9523b5c241Stomee for (Aggregation agg : a.getAggregations()) { 9623b5c241Stomee for (Tuple tuple : agg.asMap().keySet()) { 9723b5c241Stomee address = (Number)tuple.get(0).getValue(); 9823b5c241Stomee if (address instanceof Integer) { 9923b5c241Stomee int addr = (Integer)address; 10023b5c241Stomee f = consumer.lookupUserFunction(pid, addr); 10123b5c241Stomee } else { 10223b5c241Stomee long addr = (Long)address; 10323b5c241Stomee f = consumer.lookupUserFunction(pid, addr); 10423b5c241Stomee } 10523b5c241Stomee System.out.println(f); 10623b5c241Stomee } 10723b5c241Stomee } 10823b5c241Stomee consumer.close(); 10923b5c241Stomee } catch (Exception e) { 11023b5c241Stomee e.printStackTrace(); 11123b5c241Stomee System.exit(1); 11223b5c241Stomee } 11323b5c241Stomee } 11423b5c241Stomee } 115